Соединительная строка Mongodb Atlas не работает в единстве - PullRequest
0 голосов
/ 03 апреля 2020

Я пытаюсь следовать этому уроку: https://www.youtube.com/watch?v=Tc5raxEFntw&t=806s Примерно на полпути я получаю сообщение об ошибке:

ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
System.Data.Common.DbConnectionOptions.GetKeyValuePair (System.String connectionString, System.Int32 currentPosition, System.Text.StringBuilder buffer, System.Boolean useOdbcRules, System.String& keyname, System.String& keyvalue) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.Common.DbConnectionOptions.ParseInternal (System.Collections.Generic.Dictionary`2[TKey,TValue] parsetable, System.String connectionString, System.Boolean buildChain, System.Collections.Generic.Dictionary`2[TKey,TValue] synonyms, System.Boolean firstKey) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.Common.DbConnectionOptions..ctor (System.String connectionString, System.Collections.Generic.Dictionary`2[TKey,TValue] synonyms, System.Boolean useOdbcRules) (at <290425a50ff84a639f8c060e2d4530f6>:0)
System.Data.Common.DbConnectionStringBuilder.set_ConnectionString (System.String value) (at <290425a50ff84a639f8c060e2d4530f6>:0)
MongoDB.Driver.MongoConnectionStringBuilder..ctor (System.String connectionString) (at <6da29fc855c44d33ad78b3e27475ff27>:0)
MongoDB.Driver.MongoClient.ParseConnectionString (System.String connectionString) (at <6da29fc855c44d33ad78b3e27475ff27>:0)
MongoDB.Driver.MongoClient..ctor (System.String connectionString) (at <6da29fc855c44d33ad78b3e27475ff27>:0)
Mongo.Init () (at Assets/Database/Mongo.cs:17)
Server.Init () (at Assets/Scripts/Server.cs:37)
Server.Start () (at Assets/Scripts/Server.cs:26)

Единственное, что я сделал, отличается от него используется строка подключения, предоставленная Mongodb Atlas для C # /. NET версия драйвера 2.5. Я попробовал строку подключения для всех остальных версий безуспешно, я попытался использовать более общую c строку подключения.

using MongoDB.Driver;
using UnityEngine;

public class Mongo
{
    private const string MONGO_URI = "mongodb+srv://my_username:my_password@project_name-xp2bl.mongodb.net/test?retryWrites=true&w=majority";
    private const string DATABASE_NAME = "my_database";

    private MongoClient client;
    private MongoServer server;
    private MongoDatabase db;

    private MongoCollection accounts;

    public void Init()
    {
        client = new MongoClient(MONGO_URI);
        server = client.GetServer();
        db = server.GetDatabase(DATABASE_NAME);

        // Initialize collection
        accounts = db.GetCollection<Model_Account>("account");

        Debug.Log("Database Initialized");
    }
}

Буду признателен за любые предложения.

...