在类库项目中更改数据库连接字符串 [英] change database connectionstring in class library project

查看:71
本文介绍了在类库项目中更改数据库连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个解决方案中使用了多个项目,其中一个是真实项目,另一个是助手项目.这些帮助程序项目之一,我有settings.settings文件,用于存储数据库连接字符串.现在,当我构建/调试它时.我看不到任何可以更改连接字符串的文件.它已集成到helperproject的dll文件中吗?我该如何解决这个操作系统,以便我可以更改连接字符串?

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 file? How can i resolve this os that i can change the connection string please?

推荐答案

默认情况下,设计器生成的Settings类具有"internal"访问说明符. 因此,您添加的应用程序设置将在引用帮助程序集的程序集中不可见.

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.

要使其在所有引用程序集中均可见,请手动或通过设计器创建类public.查看快照.

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

将其制成public后,可以在引用了该程序集的其他项目中访问它.

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

String connectionString = TestAssembly.Settings.Default.ConnectionString;

但是最好将设置放入特定于该应用程序的应用程序配置文件中.在您的情况下,将app.config添加到主项目中;并在配置中添加connectionStrings部分.

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.

这篇关于在类库项目中更改数据库连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆