c# - 如何使用 C# 的 OrientDB-NET.binary 驱动程序在 OrientDB 上创建数据库?

标签 c# .net orientdb

我开始使用 C# 的 OrientDB-NET.binary 驱动程序来学习 OrientDB,并且我已经成功配置并运行 OrientDB 作为服务器。

现在我只是尝试使用 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/)

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

如果没有,如何在OritentDB上创建数据库?

我会感谢一些示例代码。

提前致谢!

最佳答案

我使用 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 Studio 输出:

enter image description here

第二个连接:

enter image description here

希望对你有帮助

关于c# - 如何使用 C# 的 OrientDB-NET.binary 驱动程序在 OrientDB 上创建数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37148875/

相关文章:

OrientDB SELECT 和子查询

c# - SQL0666 - SQL 查询超出指定的时间限制或存储限制

c# - 可以在Thread.Sleep期间引发ThreadAbortException吗?

.NET 设计类(class)?

orientdb - 我们如何在 Orientdb 中使用 Tinkerpop 蓝图?

javascript - 值未保存在 orientdb 类中

c# - 如何从集合中检索第一项?

c# - 找出最后一个焦点的控件

c# - 使用陈述题

.net - 用于安装 nuget 包的 PowerShell 脚本