使用 ConnectionStringBuilder 对象创建精确连接字符串

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

posted on 2008-10-22 11:05  李炜  阅读(1507)  评论(0编辑  收藏  举报

导航