引用命名空间:using System.Data.Common;
// 连接据库对象取得
DbProviderFactory dbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
using (DbConnection dbConnection = dbProviderFactory.CreateConnection())
{
// 数据库连接字符串作成
DbConnectionStringBuilder connectionStringBuilder = dbProviderFactory.CreateConnectionStringBuilder();
connectionStringBuilder.Add("Data Source", "*******");
connectionStringBuilder.Add("Integrated Security", "True");
connectionStringBuilder.Add("Initial Catalog", ""*******");
// 连接
dbConnection.ConnectionString = connectionStringBuilder.ConnectionString;
dbConnection.Open();
// 处理
.....
}