In ASP. NETProgramIn multi-layer development, we often write the data access layer in a class library. When the connection string is used in the class library, many people find the problem, because the class library finally gives others a DLL that does not contain our common web. config or app. config. In this case, when the database we use needs to change, we cannot simply change the connection string by modifying web. config or app. config.
I don't know how you solve this problem (share it). I am doing this:
1) after the class library is created, the connection string will be placed in the app. config file, for example:
Code
< Connectionstrings >
< Add Name = "Testproj. properties. settings. testconnectionstring"
Connectionstring = "Data Source =. \ sqlexpress; initial catalog = test; Integrated Security = true"
Providername = "System. Data. sqlclient" />
</ Connectionstrings >
2) In our ASP. net program, if you need to replace the connection string in this DLL, we can. config overwrites the connection string (the same name must be used), so that the connection string can be replaced. For example:
Code
< Connectionstrings >
< Add Name = "Testproj. properties. settings. testconnectionstring"
Connectionstring = "Data Source =. \ sqlexpress; initial catalog = test222; Integrated Security = true"
Providername = "System. Data. sqlclient" />
</ Connectionstrings >
In this case, the DLL uses the new database test222. The problem is not too big, but it is very practical. Hope to help you!
Have a nice day!