如何使用面向 C# 的 OrientDB-NET.binary 驱动程序在 OritentDB 上创建数据库? [英] How to create database on OritentDB using OrientDB-NET.binary driver for C#?

查看:95
本文介绍了如何使用面向 C# 的 OrientDB-NET.binary 驱动程序在 OritentDB 上创建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

现在我只是尝试使用 OClient.CreateDatabasePool 运行连接,如下所述

OrientDB Studio 输出:

第二次连接:

希望能帮到你

I'm starting to learn OrientDB using OrientDB-NET.binary driver for C# and I have successfully configured and ran OrientDB as server.

Now I just tried to run a connection using OClient.CreateDatabasePool as described here https://github.com/yojimbo87/OrientDB-NET.binary/wiki

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

and Im getting this error:

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

Is it possible to create "TestDatabaseName" database using the .NET driver?

If not, how to create database on OritentDB?

I will apreciate some sample code.

Thank you in advance!

解决方案

I created the following example using OrientDB 2.1.16 and the .NET driver. Main steps:

  1. If TestDatabaseName database already exists, I drop it;
  2. Creating a new TestDatabaseName database;
  3. Connecting and populating it.

C# CODE:

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);

           }

       }

    }

}

Output:

OrientDB Studio output:

Second connection:

Hope it helps

这篇关于如何使用面向 C# 的 OrientDB-NET.binary 驱动程序在 OritentDB 上创建数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆