I am developing a class library (C#) that i will use it for my different projects (later). My class library dll will use the connection string /data context of the project which will reference my new dll. How can i do it?
Lets say i have a class Library Project named “CLP”, and a website project “WP”. I can add reference to CLP.dll file but how i will pass a connection string/data context object to that dll? as CLP.dll will access db based on the connection string of the “WP”.
Not sure my problem is clear or not!
If you develop your class library and it requires a connection string called “ConnectionString” as long as the project you call it from has a connection string in its web/app config file of “ConnectionString” then it should be fine.
So using your project names. Your “CLP” class project with your data access code in will setup a connection using the string “ConnectionString”:
and then you code against that connection.
In the web.config file in your web project (“WP”) you add the following:
Obviously pointing to the data source etc you are using for the “WP” project.
Hope this helps.