开发者

change database connectionstring in class library project

I am using more than one projects in a solution, on e of them are real projects, others are helper projects. One of those helper projects, I have settings.settings file for storing database connection string. Now When I build/debug it. I don't see any file where I can change the connection string. Was it gone integrated in the helperproject's dll fi开发者_StackOverflow中文版le? How can i resolve this os that i can change the connection string please?


The Settings class generated by the designer has "internal" access specifier by default. So the application settings you've added will not be visible in the assembly that is referring the helper assembly.

To make it visible across the referring assemblies, make the class public manually or via the designer. See the snapshot.

change database connectionstring in class library project

After you've made it public, you can access it in other projects where this assembly is referred.

String connectionString = TestAssembly.Settings.Default.ConnectionString;

But it would be better to put the settings in a application configuration file specific to that application. In your case add an app.config to the main project; and add connectionStrings section in the config.


I think that you miss understood something. You should add at any project you want the app.config file (or web.config in case of web app / site). Then via ConfigurationManager class you should access the data in it. http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx

The app.config is automatically copied once you run/compile your project and it will have a name as youreapp.exe.config or yourelib.dll.config.

For more details read here http://www.codeproject.com/KB/files/SaveConnStringInAppConfig.aspx

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜