DBConnectionStringBuilder 对象能够验证所有可用的连接字符串设置. 它可以启动高级连接选项,如连接池,群集连接和异步访问. DBConnectionStringBuilder 创建与数据库平台无关的代码过程中扮演一个重要角色. 它派生出 SqlConnectionStringBuilder、OracleConnectionStringBuilder、OdbcConnectionStringBuilder 和 OleDbConnectionStringBuilder ,利用面向对象的特性可以容易的创建与平台无关的数据库应用程序. 用法: C# SqlConnectionStringBuilder connbuilder = new SqlConnectionStringBuilder(); connbuilder.DataSource = "localhost"; connbuilder.UserID = "user"; connbuilder.Password = "password"; connbuilder.MinPoolSize = 5; connbuilder.MaxPoolSize= 20; SqlConnection conn = new SqlConnection(connbuilder.ConnectionString); conn.Open();
DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); builder.ConnectionString = accountSet.DBSetting.ConnectionString; object dataSource = null; if (builder.TryGetValue(Const.DATASOURCE, out dataSource)) { serverModel.DBIP = dataSource.ToString().Trim(); }
原文地址:http://www.cnblogs.com/waylee/archive/2008/10/22/1316571.html