当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionString类代码示例

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


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

示例1: AssertValid

        private void AssertValid(ConnectionString connectionString, BsonDocument definition)
        {
            if (!definition["valid"].ToBoolean())
            {
                Assert.Fail($"The connection string '{definition["uri"]}' should be invalid.");
            }

            BsonValue readConcernValue;
            if (definition.TryGetValue("readConcern", out readConcernValue))
            {
                var readConcern = ReadConcern.FromBsonDocument((BsonDocument)readConcernValue);

                connectionString.ReadConcernLevel.Should().Be(readConcern.Level);
            }

            BsonValue writeConcernValue;
            if (definition.TryGetValue("writeConcern", out writeConcernValue))
            {
                var writeConcern = WriteConcern.FromBsonDocument(MassageWriteConcernDocument((BsonDocument)writeConcernValue));

                connectionString.W.Should().Be(writeConcern.W);
                connectionString.WTimeout.Should().Be(writeConcern.WTimeout);
                connectionString.Journal.Should().Be(writeConcern.Journal);
                connectionString.FSync.Should().Be(writeConcern.FSync);
            }
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:26,代码来源:ConnectionStringTestRunner.cs

示例2: With_an_ipv4_host

        public void With_an_ipv4_host()
        {
            var subject = new ConnectionString("mongodb://127.0.0.1");

            subject.Hosts.Count().Should().Be(1);
            subject.Hosts[0].Should().Be(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 27017));
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:7,代码来源:ConnectionStringTests.cs

示例3: With_one_host_and_port

        public void With_one_host_and_port()
        {
            var subject = new ConnectionString("mongodb://localhost:27092");

            subject.Hosts.Count().Should().Be(1);
            subject.Hosts.Single().Should().Be(new DnsEndPoint("localhost", 27092));
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:7,代码来源:ConnectionStringTests.cs

示例4: Execute

        //public List<string> Execute(string qry)
        //{
        //    ConnectionString cnString = new ConnectionString();
        //    IDbConnection cn = new OleDbConnection(cnString.GetConnString());
        //    IDbCommand cmd = new OleDbCommand(qry, (OleDbConnection)cn);
        //    List<string> contents = new List<string>();
        //    try
        //    {
        //        // open the connection
        //        cn.Open();
        //        // execute the query
        //        // read the data into a data reader
        //        IDataReader rdr = cmd.ExecuteReader();
        //        while (rdr.Read())
        //        {
        //            for (int i = 0; i < rdr.FieldCount; i++)
        //            {
        //                contents.Add(rdr[i].ToString());
        //            }
        //        }
        //        return contents;
        //    }
        //    catch (Exception)
        //    {
        //    }
        //    finally
        //    {
        //        cn.Close();
        //    }
        //        return contents;
        //}
        public DataTable Execute(string qry)
        {
            ConnectionString cnString = new ConnectionString();
            IDbConnection cn = new OleDbConnection(cnString.GetConnString());
            IDbCommand cmd = new OleDbCommand(qry, (OleDbConnection)cn);
            //List<DbUser> contents = new List<DbUser>();
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter((OleDbCommand)cmd);

            try
            {
                // open the connection
                cn.Open();
                da.Fill(dt);

                //contents = (from DataRow row in dt.Rows

                //                select new DbUser
                //                {
                //                    UserId = (int)row["SHARE_HOLDER_ID"],
                //                    FirstName = row["FIRST_NAME"].ToString(),
                //                    LastName = row["LAST_NAME"].ToString()

                //                }).ToList();
            }
            catch (Exception)
            {
            }
            finally
            {
                cn.Close();
            }
            return dt;
        }
开发者ID:hksarwar,项目名称:JobSystem,代码行数:65,代码来源:ReadCommand.cs

示例5: AssertValid

        private void AssertValid(ConnectionString connectionString, BsonDocument definition)
        {
            if (!definition["valid"].ToBoolean())
            {
                Assert.Fail($"The connection string '{definition["uri"]}' should be invalid.");
            }

            var hostsValue = definition["hosts"] as BsonArray;
            if (hostsValue != null)
            {
                var expectedEndPoints = hostsValue
                    .Select(x => ConvertExpectedHostToEndPoint((BsonDocument)x))
                    .ToList();

                var missing = expectedEndPoints.Except(connectionString.Hosts, EndPointHelper.EndPointEqualityComparer);
                missing.Any().Should().Be(false);

                var additions = connectionString.Hosts.Except(expectedEndPoints, EndPointHelper.EndPointEqualityComparer);
                additions.Any().Should().Be(false);
            }

            var authValue = definition["auth"] as BsonDocument;
            if (authValue != null)
            {
                connectionString.DatabaseName.Should().Be(ValueToString(authValue["db"]));
                connectionString.Username.Should().Be(ValueToString(authValue["username"]));
                connectionString.Password.Should().Be(ValueToString(authValue["password"]));
            }
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:29,代码来源:TestRunner.cs

示例6: GetCommand

        public bool GetCommand(int jobId, Guid sessionId, string commentText)
        {
            ConnectionString cnString = new ConnectionString();
            IDbConnection cn = new OleDbConnection(cnString.GetConnString());

            IDbCommand cmd = new OleDbCommand("sp_add_comment", (OleDbConnection)cn);
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                cn.Open();

                //Get user id
                FindUser find = new FindUser();
                int userId = int.Parse(find.GetUserIDBySessionId(sessionId).ToString());

                cmd.Parameters.Add(new OleDbParameter("@user_id", userId));
                cmd.Parameters.Add(new OleDbParameter("@job_id", jobId));
                cmd.Parameters.Add(new OleDbParameter("@comText", commentText));

                cmd.ExecuteNonQuery();
                return true;

            }
            catch(OleDbException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                cn.Close();
            }

            return false;
        }
开发者ID:hksarwar,项目名称:JobSystem,代码行数:35,代码来源:InsertComment.cs

示例7: Execute

        public bool Execute(string qry)
        {
            ConnectionString cnString = new ConnectionString();
            IDbConnection cn = new OleDbConnection(cnString.GetConnString());
            IDbCommand cmd = new OleDbCommand(qry, (OleDbConnection)cn);
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                cn.Open();
                IDbTransaction tran = cn.BeginTransaction();
                cmd.Transaction = tran;

                int affectedRows = cmd.ExecuteNonQuery();
                Console.WriteLine(affectedRows);
                if (affectedRows > 0)
                {
                    tran.Commit();
                    return true;
                }
                else
                {
                    tran.Rollback();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                cn.Close();
            }
            return false;
        }
开发者ID:hksarwar,项目名称:JobSystem,代码行数:35,代码来源:WriteProcedureCommand.cs

示例8: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            //Configure the automapper
            AutoMapperConfiguration.Configure();

            //Configure DataAccess service
            var connString = new ConnectionString("localhost", 5432, "webtest", "postgres", "P0stgr3s");
            services.AddDataAccess<MyDataContext>(opt =>
            {
                opt.ConnectionString = connString;
                opt.DbConfiguration = new PostgresDbConfiguration();
                opt.DefaultSchema = "public";
                opt.PluralizeTableNames = false;
            });

            //Use the default CodetableDiscoveryOptions
            //services.AddCodetableDiscovery();

            //Use the custom CodetableDiscoveryOptions
            services.AddCodetableDiscovery(options =>
            {
                options.Route = "custom/codetables";
            });

            services.AddMvc();
        }
开发者ID:digipolisantwerp,项目名称:codetable_aspnetcore,代码行数:27,代码来源:Startup.cs

示例9: EmbeddedDataObjectContext

 /// <summary>
 /// Create a new instance of the context that attaches to the specified directory location
 /// </summary>
 /// <param name="connectionString">The Brightstar service connection string</param>
 /// <remarks>The data context is thread-safe but doesn't support concurrent access to the same base location by multiple
 /// instances. You should ensure in your code that only one EmbeddedDataObjectContext instance is connected to any given base location
 /// at a given time.</remarks>
 public EmbeddedDataObjectContext(ConnectionString connectionString)
 {
     if (connectionString == null) throw new ArgumentNullException("connectionString");
     if (connectionString.Type != ConnectionType.Embedded) throw new ArgumentException("Invalid connection type", "connectionString");
     _serverCore = ServerCoreManager.GetServerCore(connectionString.StoresDirectory);
     _optimisticLockingEnabled = connectionString.OptimisticLocking;
 }
开发者ID:Garwin4j,项目名称:BrightstarDB,代码行数:14,代码来源:EmbeddedDataObjectContext.cs

示例10: WebConfigParser

 public WebConfigParser(string fileName)
 {
     _xmlDoc = new XmlDocument();
     _xmlDoc.Load(fileName);
     _appSettings = new AppSetting(_xmlDoc);
     _connStrings = new ConnectionString(_xmlDoc);
 }
开发者ID:danni95,项目名称:Core,代码行数:7,代码来源:WebConfigParser.cs

示例11: DefaultProvider_EmptyCommandLine_Throws

 public void DefaultProvider_EmptyCommandLine_Throws()
 {
     var provider = Provider.Default;
     var commandLine = new CommandLine();
     var connectionString = new ConnectionString();
     var result = ConnectionStringBuilder.GetConnectionString(provider, commandLine, connectionString);
 }
开发者ID:jhgbrt,项目名称:SqlConsole,代码行数:7,代码来源:ConnectionStringBuilderTests.cs

示例12: DefaultProvider_invalidCommandLine_Throws

 public void DefaultProvider_invalidCommandLine_Throws()
 {
     var provider = Provider.Default;
     var commandLine = new CommandLine {[CommandLineParam.user] = Value.From("user")};
     var connectionString = new ConnectionString();
     var result = ConnectionStringBuilder.GetConnectionString(provider, commandLine, connectionString);
 }
开发者ID:jhgbrt,项目名称:SqlConsole,代码行数:7,代码来源:ConnectionStringBuilderTests.cs

示例13: FileDiskService

        public FileDiskService(string connectionString, Logger log)
        {
            var str = new ConnectionString(connectionString);

            _filename = str.GetValue<string>("filename", "");
            var journalEnabled = str.GetValue<bool>("journal", true);
            _timeout = str.GetValue<TimeSpan>("timeout", new TimeSpan(0, 1, 0));
            _readonly = str.GetValue<bool>("readonly", false);
            _password = str.GetValue<string>("password", null);
            _initialSize = str.GetFileSize("initial size", 0);
            _limitSize = str.GetFileSize("limit size", 0);
            var level = str.GetValue<byte?>("log", null);

            // simple validations
            if (string.IsNullOrWhiteSpace(_filename)) throw new ArgumentNullException("filename");
            if (_initialSize > 0 && _initialSize < (BasePage.PAGE_SIZE * 10)) throw new ArgumentException("initial size too low");
            if (_limitSize > 0 && _limitSize < (BasePage.PAGE_SIZE * 10)) throw new ArgumentException("limit size too low");
            if (_initialSize > 0 && _limitSize > 0 && _initialSize > _limitSize) throw new ArgumentException("limit size less than initial size");

            // setup log + log-level
            _log = log;
            if(level.HasValue) _log.Level = level.Value;

            _journalEnabled = _readonly ? false : journalEnabled; // readonly? no journal
            _journalFilename = Path.Combine(Path.GetDirectoryName(_filename), Path.GetFileNameWithoutExtension(_filename) + "-journal" + Path.GetExtension(_filename));
            _tempFilename = Path.Combine(Path.GetDirectoryName(_filename), Path.GetFileNameWithoutExtension(_filename) + "-temp" + Path.GetExtension(_filename));
        }
开发者ID:ktaranov,项目名称:LiteDB,代码行数:27,代码来源:FileDiskService.cs

示例14: GetCommand

        public bool GetCommand(int commentId)
        {
            ConnectionString cnString = new ConnectionString();
            IDbConnection cn = new OleDbConnection(cnString.GetConnString());

            IDbCommand cmd = new OleDbCommand("sp_delete_comment", (OleDbConnection)cn);
            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                cn.Open();

                cmd.Parameters.Add(new OleDbParameter("@comment_id", commentId));

                cmd.ExecuteNonQuery();
                return true;

            }
            catch (OleDbException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                cn.Close();
            }

            return false;
        }
开发者ID:hksarwar,项目名称:JobSystem,代码行数:29,代码来源:DeleteComment.cs

示例15: ODAL

        /// <summary>
        /// 資料庫連線名稱ByString
        /// </summary>
        /// <param name="Connection"></param>
        public ODAL(string Connection)
        {
            objCon = new ConnectionString(Connection);
                cmd = GetDbCommand;
                if (objCon.ProviderName == "System.Data.SqlClient")
                {
                    Provider = new MSSQL(objCon);
                }
                else if (objCon.ProviderName == "System.Data.OleDb")
                {
                    Provider = new OleDb(objCon);
                }
                else if (objCon.ProviderName == "System.Data.OracleClient")
                {
                    Provider = new Oracle(objCon);
                }
                else if (objCon.ProviderName == "MySql.Data.MySqlClient")
                {
                    Provider = new Mysql(objCon);
                }
                else
                {
                    throw new Exception("需指定資料庫類型!");

                }
        }
开发者ID:chrislin123,项目名称:M10Service,代码行数:30,代码来源:ODAL.cs


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