2016-05-10 39 views
1

我开始学习使用OrientDB-NET.binary驱动程序进行C#编程的OrientDB,并且我已经成功配置并将OrientDB作为服务器运行。如何使用OrientDB-NET.binary驱动程序为C#在OritentDB上创建数据库?

现在,我只是试图运行使用OClient.CreateDatabasePool连接这里描述https://github.com/yojimbo87/OrientDB-NET.binary/wiki

OClient.CreateDatabasePool(
"127.0.0.1", 
2424, 
"TestDatabaseName", 
ODatabaseType.Graph, 
"admin", 
"admin", 
10, 
"myTestDatabaseAlias"); 

和进出口收到此错误:

com.orientechnologies.orient.core.exception.OConfigurationException: Database 'TestManualy' is not configured on server (home=E:/orientdb-community-2.1.16/databases/) 

是否有可能使用的是创建“TestDatabaseName”数据库.NET驱动程序?

如果不是,如何在OritentDB上创建数据库?

我会补充一些示例代码。

预先感谢您!

回答

1

我使用OrientDB 2.1.16和.NET驱动程序创建了以下示例。主要步骤:

  1. 如果TestDatabaseName数据库已经存在,我把它放下;
  2. 创建一个新的TestDatabaseName数据库;
  3. 连接并填充它。

C#代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Orient.Client; 

namespace OrientTestCreateDB 

{ 
    class CreateDB 

    { 

    private static string _hostname = "127.0.0.1"; 
    private static int _port = 2424; 
    private static string _rootUserName = "root"; 
    private static string _rootUserPassword = "root"; 

    private static OServer _server; 

    private static string _DBname = "TestDatabaseName"; 
    private static string _username = "admin"; 
    private static string _password = "admin"; 

    static void Main(string[] args) 

    { 

     _server = new OServer(_hostname, _port, _rootUserName, _rootUserPassword); 

     //If the DB already exists I delete it 
     if (_server.DatabaseExist(_DBname, OStorageType.PLocal)) 

     { 

      _server.DropDatabase("TestDatabaseName", OStorageType.PLocal); 

      Console.WriteLine("Database " + _DBname + " deleted"); 

     } 

     //Creating the new DB 
     _server.CreateDatabase(_DBname, ODatabaseType.Graph, OStorageType.PLocal); 

     Console.WriteLine("Database " + _DBname + " created"); 

     //Connect to the DB and populate it 
     OClient.CreateDatabasePool(
     "127.0.0.1", 
     2424, 
     _DBname, 
     ODatabaseType.Graph, 
     _username, 
     _password, 
     10, 
     "myTestDatabaseAlias" 
     ); 

     Console.WriteLine("Connected to the DB " + _DBname); 

     using (ODatabase database = new ODatabase("myTestDatabaseAlias")) 

      { 

       database 
        .Create.Class("TestClass") 
        .Extends<OVertex>() 
        .Run(); 

       OVertex createdVertex = database 
        .Create.Vertex("TestClass") 
        .Set("name", "LucaS") 
        .Run(); 

       Console.WriteLine("Created vertex with @rid " + createdVertex.ORID); 

      } 

     } 

    } 

} 

输出:

enter image description here

OrientDB工作室输出:

enter image description here

第二个连接:

enter image description here

希望它可以帮助

+0

我不能运行代码。女巫的版本是什么?我使用orientdb-community-2.1.16和OrientDB-NET.binary 0.2.1,.NET 4.5.2。这枚枚举不存在OStorageType.PLocal,我改为OStorageType.Local,我发现枚举。 _server.DatabaseExist(_DBname,OStorageType.PLocal)只接受一个参数。 OVertex并不存在。 – user1203003

+0

嗨,这些是我的规格:ODB社区2.1.16,ODB-NET 0.2.1,Visual Studio 2015.第一次我没有遇到这个问题,因为我没有使用nuget,但我只创建了一个' Orient.Client.dll'。无论如何,我试图通过使用nuget,我遇到了同样的问题。我通过从我的项目中删除了“Orient.Client.dll”引用来解决它,然后使用“添加引用...”重新导入它。可能是第一次参考文件没有正确创建,你可以尝试这些说明吗? – LucaS

+0

是的,我用nuget。现在我试着编译和引用dll,它工作。非常感谢。 – user1203003

相关问题