But I meet two more confused at work:
A, find someone with & lt; AppSettings> Configure the database connection string, when you see this, can only sigh my knowledge is too short!
Second, it is in the c # code, often see instantiation database connection object, use the following way almost all search on the net also is this way,
String connstr=ConfigurationManager. ConnectionStrings [r]. "myconn" ConnectionString;
Using (SqlConnection conn=new SqlConnection (connstr))
{
.
}
But the.net provides use the factory pattern to implement:
ConnectionStringSettings myconn=ConfigurationManager. ConnectionStrings [" myconn "];
DbProviderFactory factory=DbProviderFactories. GetFactory (myconn. ProviderName);
Using (DbConnection conn=factory. The CreateConnection ()) {
Conn. The ConnectionString=set. The ConnectionString;
.
}
Use the factory pattern is more flexible and realize multiple database support more convenient,
This is a personal opinion only,
CodePudding user response:
Good idea, is worth using for reference