为了在不作修改的情况下改变这种联系,你应当采取以下程序:
- Create a SqlConnectionStringBuilder object Assign your original connection string to it
- Change the parameters that you want in the created SqlConnectionStringBuilder object.
- Adding the SqlConnectionStringBuilder ConnectionString property to your DbConnection Object.
参看以下例子:(假设首先,你是用你原来的拼凑(此处称db))创造出正常的DbConnection:
if (db != null)
{
SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder(db.ConnectionString)
{ ConnectTimeout = 5, InitialCatalog = "your CatalogName" }; // you can add other parameters.
db.ConnectionString = conn.ConnectionString;
db.Open();
return true;
}
}
In the given example, the Initial Catalog and the timeout were changed without touch the original string.
我希望这有助于你。