• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Driver.MongoConnectionStringBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoDB.Driver.MongoConnectionStringBuilder的典型用法代码示例。如果您正苦于以下问题:C# MongoConnectionStringBuilder类的具体用法?C# MongoConnectionStringBuilder怎么用?C# MongoConnectionStringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoConnectionStringBuilder类属于MongoDB.Driver命名空间,在下文中一共展示了MongoConnectionStringBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            MongoConnectionStringBuilder builder = new MongoConnectionStringBuilder();
            builder.Server = new MongoServerAddress("localhost", 27017);
            builder.DatabaseName = "douban";

            MongoServer mongo = MongoServer.Create(builder);
            mongo.Connect();
            var db = mongo.GetDatabase("douban");

            SqlConnectionStringBuilder sqlconnbuilder = new SqlConnectionStringBuilder();
            sqlconnbuilder.DataSource = "localhost\\s2012";
            sqlconnbuilder.InitialCatalog = "douban";
            sqlconnbuilder.IntegratedSecurity = true;

            SqlConnection sql = new SqlConnection(sqlconnbuilder.ToString());
            sql.Open();

            var cmd = sql.CreateCommand();

            InsertGroup(mongo, db, cmd);

            //InsertGroupPost(mongo, db, cmd);



        }
开发者ID:cuicheng11165,项目名称:Mongo-Demo,代码行数:27,代码来源:Program.cs


示例2: TestConnectTimeout

        public void TestConnectTimeout()
        {
            string connectionString = "server=localhost;connectTimeout=123";
            var builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(TimeSpan.FromSeconds(123), builder.ConnectTimeout);
            Assert.AreEqual(connectionString + "s", builder.ToString()); // "s" units added

            connectionString = "server=localhost;connectTimeout=123ms";
            builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(TimeSpan.FromMilliseconds(123), builder.ConnectTimeout);
            Assert.AreEqual(connectionString, builder.ToString());

            connectionString = "server=localhost;connectTimeout=123s";
            builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(TimeSpan.FromSeconds(123), builder.ConnectTimeout);
            Assert.AreEqual(connectionString, builder.ToString());

            connectionString = "server=localhost;connectTimeout=123m";
            builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(TimeSpan.FromMinutes(123), builder.ConnectTimeout);
            Assert.AreEqual(connectionString, builder.ToString());

            connectionString = "server=localhost;connectTimeout=123h";
            builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(TimeSpan.FromHours(123), builder.ConnectTimeout);
            Assert.AreEqual(connectionString, builder.ToString());
        }
开发者ID:javanal,项目名称:mongo-csharp-driver,代码行数:27,代码来源:MongoConnectionStringBuilderTests.cs


示例3: MongoBind

 public MongoBind(string host, int port, string database, string collection)
 {
     var builder = new MongoConnectionStringBuilder {Server = new MongoServerAddress(host, port)};
     Client = new MongoClient(builder.ConnectionString);
     Database = Client.GetServer().GetDatabase(database);
     Collection = Database.GetCollection(collection);
 }
开发者ID:ktj007,项目名称:mmo,代码行数:7,代码来源:MongoBind.cs


示例4: TestDefaults

 public void TestDefaults() {
     string connectionString = "server=localhost";
     var builder = new MongoConnectionStringBuilder(connectionString);
     Assert.IsNull(builder.Username);
     Assert.IsNull(builder.Password);
     Assert.AreEqual(1, builder.Servers.Count());
     Assert.AreEqual("localhost", builder.Servers.Single().Host);
     Assert.AreEqual(27017, builder.Servers.Single().Port);
     Assert.IsNull(builder.DatabaseName);
     Assert.AreEqual(ConnectionMode.Direct, builder.ConnectionMode);
     Assert.AreEqual(MongoDefaults.ConnectTimeout, builder.ConnectTimeout);
     Assert.AreEqual(MongoDefaults.GuidRepresentation, builder.GuidRepresentation);
     Assert.AreEqual(false, builder.IPv6);
     Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, builder.MaxConnectionIdleTime);
     Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, builder.MaxConnectionLifeTime);
     Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, builder.MaxConnectionPoolSize);
     Assert.AreEqual(null, builder.ReplicaSetName);
     Assert.IsNull(builder.SafeMode);
     Assert.AreEqual(false, builder.SlaveOk);
     Assert.AreEqual(MongoDefaults.SocketTimeout, builder.SocketTimeout);
     Assert.AreEqual(MongoDefaults.WaitQueueMultiple, builder.WaitQueueMultiple);
     Assert.AreEqual(MongoDefaults.WaitQueueSize, builder.WaitQueueSize);
     Assert.AreEqual(MongoDefaults.WaitQueueTimeout, builder.WaitQueueTimeout);
     Assert.AreEqual(connectionString, builder.ToString());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:25,代码来源:MongoConnectionStringBuilderTests.cs


示例5: btConnect_Click

 private void btConnect_Click(object sender, EventArgs e)
 {
     if(!ServerConnection.Connected)
     {
         try
         {
             var connectionString = new MongoConnectionStringBuilder();
             connectionString.Server = new MongoServerAddress(tbServerAddress.Text);
             connectionString.Username = tbUser.Text;
             connectionString.Password = tbPassword.Text;
             connectionString.DatabaseName = "test";
             //new ServerConnection(tbServerAddress.Text);
             new ServerConnection(connectionString);
             //FillComboboxWithDatabaseNames(ServerConnection.Server);
             SetConnectedState();
         }
         catch(Exception ex)
         {
             MessageBox.Show(ex.Message);
             tbServerAddress.Focus();
         }
     }
     else
     {
         //ServerConnection.DatabaseName = cbDatabases.Text;
         ServerConnection.DatabaseName = "test";
         CloseLoginFormOpenMain();
     }
 }
开发者ID:dr-dead,项目名称:diplomaWork,代码行数:29,代码来源:loginForm.cs


示例6: TestDefaults

        public void TestDefaults()
        {
            var builder = new MongoConnectionStringBuilder();
            Assert.AreEqual(null, builder.Username);
            Assert.AreEqual(null, builder.Password);
            Assert.AreEqual(null, builder.Server);
            Assert.AreEqual(null, builder.Servers);
            Assert.AreEqual(null, builder.DatabaseName);
            Assert.AreEqual(ConnectionMode.Automatic, builder.ConnectionMode);
            Assert.AreEqual(MongoDefaults.ConnectTimeout, builder.ConnectTimeout);
            Assert.AreEqual(MongoDefaults.GuidRepresentation, builder.GuidRepresentation);
            Assert.AreEqual(false, builder.IPv6);
            Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, builder.MaxConnectionIdleTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, builder.MaxConnectionLifeTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, builder.MaxConnectionPoolSize);
            Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, builder.MinConnectionPoolSize);
            Assert.AreEqual(null, builder.ReadPreference);
            Assert.AreEqual(null, builder.ReplicaSetName);
            Assert.AreEqual(null, builder.SafeMode);
            Assert.AreEqual(MongoDefaults.SecondaryAcceptableLatency, builder.SecondaryAcceptableLatency);
#pragma warning disable 618
            Assert.AreEqual(false, builder.SlaveOk);
#pragma warning restore
            Assert.AreEqual(MongoDefaults.SocketTimeout, builder.SocketTimeout);
            Assert.AreEqual(false, builder.UseSsl);
            Assert.AreEqual(MongoDefaults.WaitQueueMultiple, builder.WaitQueueMultiple);
            Assert.AreEqual(MongoDefaults.WaitQueueSize, builder.WaitQueueSize);
            Assert.AreEqual(MongoDefaults.WaitQueueTimeout, builder.WaitQueueTimeout);
            Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, builder.ComputedWaitQueueSize);

            var connectionString = ""; // not actually a valid connection string because it's missing the host
            Assert.AreEqual(connectionString, builder.ToString());
        }
开发者ID:staywellandy,项目名称:mongo-csharp-driver,代码行数:33,代码来源:MongoConnectionStringBuilderTests.cs


示例7: TestToStringOutput

        public void TestToStringOutput()
        {
            var builder = new MongoConnectionStringBuilder { Password = "testpassword", Username = "testusername", ConnectionLifetime = TimeSpan.FromSeconds (50), MaximumPoolSize = 101, MinimumPoolSize = 202, ConnectionTimeout = TimeSpan.FromSeconds(60)};
            builder.AddServer ("testserver1", 555);
            builder.AddServer ("testserver2");

            Assert.AreEqual ("Username=testusername;Password=testpassword;Server=testserver1:555,testserver2;MaximumPoolSize=101;MinimumPoolSize=202;ConnectionTimeout=60;ConnectionLifetime=50", builder.ToString ());
        }
开发者ID:kvnsmth,项目名称:mongodb-csharp,代码行数:8,代码来源:TestConnectionStringBuilder.cs


示例8: Connect

 public static CountersDatabase Connect(string host, int? port, string dbName)
 {
     MongoConnectionStringBuilder builder = new MongoConnectionStringBuilder();
     builder.SocketTimeout = new TimeSpan(0, 30, 0);
     builder.Server = port.HasValue ? new MongoServerAddress(host, port.Value) : new MongoServerAddress(host);
     MongoServer server = MongoServer.Create(builder);
     server.Connect();
     MongoDatabase db = server.GetDatabase(dbName);
     return new CountersDatabase(server, db);
 }
开发者ID:demonix,项目名称:iPoint.ServiceStatistics,代码行数:10,代码来源:CountersDatabase.cs


示例9: TestConnectionStringParsingServerWithoutPort

        public void TestConnectionStringParsingServerWithoutPort()
        {
            var builder = new MongoConnectionStringBuilder ("Username=testuser;Password=testpassword;Server=testserver");
            Assert.AreEqual ("testuser", builder.Username);
            Assert.AreEqual ("testpassword", builder.Password);

            var servers = new List<MongoServerEndPoint> (builder.Servers);
            Assert.AreEqual (1, servers.Count);
            Assert.AreEqual ("testserver", servers[0].Host);
            Assert.AreEqual (MongoServerEndPoint.DefaultPort, servers[0].Port);
        }
开发者ID:kvnsmth,项目名称:mongodb-csharp,代码行数:11,代码来源:TestConnectionStringBuilder.cs


示例10: TestHostWithPort

 public void TestHostWithPort() {
     string connectionString = "server=mongo.xyz.com:12345";
     var builder = new MongoConnectionStringBuilder(connectionString);
     Assert.IsNull(builder.Username);
     Assert.IsNull(builder.Password);
     Assert.AreEqual(1, builder.Servers.Count());
     Assert.AreEqual("mongo.xyz.com", builder.Servers.Single().Host);
     Assert.AreEqual(12345, builder.Servers.Single().Port);
     Assert.AreEqual(ConnectionMode.Direct, builder.ConnectionMode);
     Assert.AreEqual(null, builder.ReplicaSetName);
     Assert.AreEqual(connectionString, builder.ToString());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoConnectionStringBuilderTests.cs


示例11: MyContext

 public MyContext(string connString)
 {
     /*
     var con = new MongoConnectionStringBuilder(connString);
     var server = MongoServer.Create(con);
     DB = server.GetDatabase(con.DatabaseName);
     */
     var con = new MongoConnectionStringBuilder(connString);
     var client = new MongoClient(connString);
     var server = client.GetServer();
     DB = server.GetDatabase(con.DatabaseName);
 }
开发者ID:navarradeveloper,项目名称:mongodb,代码行数:12,代码来源:MyContext.cs


示例12: TestConnectionMode

        public void TestConnectionMode()
        {
            string connectionString = "server=localhost;connect=direct";
            var builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(ConnectionMode.Direct, builder.ConnectionMode);
            Assert.AreEqual(connectionString, builder.ToString());

            connectionString = "server=localhost;connect=replicaSet";
            builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual(ConnectionMode.ReplicaSet, builder.ConnectionMode);
            Assert.AreEqual(connectionString, builder.ToString());
        }
开发者ID:javanal,项目名称:mongo-csharp-driver,代码行数:12,代码来源:MongoConnectionStringBuilderTests.cs


示例13: MongoHelper

 static MongoHelper()
 {
     if (Configuration.ConnectionString.StartsWith("mongodb://"))
     {
         IsConnectionUrl = true;
         ConnectionUrl = new MongoUrlBuilder(Configuration.ConnectionString);
     }
     else
     {
         ConnectionString = new MongoConnectionStringBuilder(Configuration.ConnectionString);
     }
 }
开发者ID:yfann,项目名称:Gallery,代码行数:12,代码来源:MongoHelper.cs


示例14: ParseConnectionString

 // private static methods
 private static MongoClientSettings ParseConnectionString(string connectionString)
 {
     if (connectionString.StartsWith("mongodb://"))
     {
         var url = new MongoUrl(connectionString);
         return MongoClientSettings.FromUrl(url);
     }
     else
     {
         var builder = new MongoConnectionStringBuilder(connectionString);
         return MongoClientSettings.FromConnectionStringBuilder(builder);
     }
 }
开发者ID:subbuballa,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoClient.cs


示例15: TestOneIPv6AddressWithPort

        public void TestOneIPv6AddressWithPort()
        {
            var connectionString = "mongodb://[::1:]:1234/?w=1";
            var url = new MongoUrl(connectionString);
            Assert.AreEqual("[::1:]", url.Server.Host);
            Assert.AreEqual(1234, url.Server.Port);
            Assert.AreEqual(true, url.SafeMode.Enabled);

            connectionString = "server=[::1:]:1234;w=1";
            var builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual("[::1:]", builder.Server.Host);
            Assert.AreEqual(1234, builder.Server.Port);
            Assert.AreEqual(true, builder.SafeMode.Enabled);
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:14,代码来源:CSharp346Tests.cs


示例16: CREATE_CLIENT

   public void CREATE_CLIENT()
   {
 
       MongoConnectionStringBuilder builder = new MongoConnectionStringBuilder();
       builder.Journal = true;
       builder.Server = new MongoServerAddress("localhost");
       string connectionString = builder.ToString();
      
       client = new MongoClient(connectionString);
       
       //client.GetServer().GetDatabase("EventStore").Drop();
       BsonClassMap.RegisterClassMap<Events.SampleEvent>();
       BsonClassMap.RegisterClassMap<Events.SampleID>();
   }
开发者ID:jcwrequests,项目名称:WYS.MongoDB.EventStore,代码行数:14,代码来源:EventStore.cs


示例17: TestOneIPv6Address

        public void TestOneIPv6Address()
        {
            var connectionString = "mongodb://[::1:]/?safe=true";
            var url = new MongoUrl(connectionString);
            Assert.AreEqual("[::1:]", url.Server.Host);
            Assert.AreEqual(27017, url.Server.Port);
            Assert.AreEqual(true, url.SafeMode.Enabled);

            connectionString = "server=[::1:];safe=true";
            var builder = new MongoConnectionStringBuilder(connectionString);
            Assert.AreEqual("[::1:]", builder.Server.Host);
            Assert.AreEqual(27017, builder.Server.Port);
            Assert.AreEqual(true, builder.SafeMode.Enabled);
        }
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:14,代码来源:CSharp346Tests.cs


示例18: TestTwoHosts

 public void TestTwoHosts() {
     string connectionString = "server=mongo1.xyz.com,mongo2.xyz.com";
     var builder = new MongoConnectionStringBuilder(connectionString);
     Assert.IsNull(builder.Username);
     Assert.IsNull(builder.Password);
     Assert.AreEqual(2, builder.Servers.Count());
     Assert.AreEqual("mongo1.xyz.com", builder.Servers.First().Host);
     Assert.AreEqual(27017, builder.Servers.First().Port);
     Assert.AreEqual("mongo2.xyz.com", builder.Servers.Skip(1).Single().Host);
     Assert.AreEqual(27017, builder.Servers.Skip(1).Single().Port);
     Assert.AreEqual(ConnectionMode.ReplicaSet, builder.ConnectionMode);
     Assert.AreEqual(null, builder.ReplicaSetName);
     Assert.AreEqual(connectionString, builder.ToString());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoConnectionStringBuilderTests.cs


示例19: TestConnectionStringParsing

        public void TestConnectionStringParsing()
        {
            var builder = new MongoConnectionStringBuilder ("Username=testuser;Password=testpassword;Server=testserver:555;ConnectionLifetime=50;MaximumPoolSize=101;MinimumPoolSize=202;Pooled=false");
            Assert.AreEqual ("testuser", builder.Username);
            Assert.AreEqual ("testpassword", builder.Password);
            Assert.AreEqual (101, builder.MaximumPoolSize);
            Assert.AreEqual (202, builder.MinimumPoolSize);
            Assert.AreEqual (TimeSpan.FromSeconds (50), builder.ConnectionLifetime);
            Assert.AreEqual (false, builder.Pooled);

            var servers = new List<MongoServerEndPoint>(builder.Servers);
            Assert.AreEqual (1, servers.Count);
            Assert.AreEqual ("testserver", servers[0].Host);
            Assert.AreEqual (555, servers[0].Port);
        }
开发者ID:kvnsmth,项目名称:mongodb-csharp,代码行数:15,代码来源:TestConnectionStringBuilder.cs


示例20: TestHostWithPort

        public void TestHostWithPort()
        {
            var builder = new MongoConnectionStringBuilder() { Server = new MongoServerAddress("mongo.xyz.com", 12345) };
            Assert.IsNull(builder.Username);
            Assert.IsNull(builder.Password);
            Assert.AreEqual(1, builder.Servers.Count());
            Assert.AreEqual("mongo.xyz.com", builder.Server.Host);
            Assert.AreEqual(12345, builder.Server.Port);
            Assert.AreEqual(null, builder.DatabaseName);
            Assert.AreEqual(ConnectionMode.Automatic, builder.ConnectionMode);

            var connectionString = "server=mongo.xyz.com:12345";
            Assert.AreEqual(connectionString, builder.ToString());
            Assert.AreEqual(connectionString, new MongoConnectionStringBuilder(connectionString).ToString());
        }
开发者ID:staywellandy,项目名称:mongo-csharp-driver,代码行数:15,代码来源:MongoConnectionStringBuilderTests.cs



注:本文中的MongoDB.Driver.MongoConnectionStringBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Driver.MongoCredentials类代码示例发布时间:2022-05-26
下一篇:
C# Driver.MongoCollectionSettings类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap