为什么connectionstring的配置是只读的?
很抱歉再次提出很多问题,但我还没有找到解决我的问题的答案。 首先: 我有一个网络(客户内联网,仅供内部使用),用户应该决定,应该显示女巫项目。每个项目都与不同服务器上的数据库有连接。所以我必须将连接字符串更改为正确的数据库,否则我必须安装同一个网络两次或更多次。 我无法使用不同的连接字符串名称,因为数据集设计器将连接名称硬编码在 c#-designer-code 中。
现在真的有办法在 global.asax.cs 中设置项目连接字符串吗? 或者用另一种方法来处理这个问题?
Sorry for the many asked question again, but i have not found a answer for solving my problem.
First of all:
I have a Web (customer-intranet, internal use only) where the user should decide, witch project should be shown. Every project has a connection to a database on different servers. So I have to change the connectionstring to the right database or I have to install the same web twice or more.
I cannot use different connectstring-names, because the the dataset-designer stores the connectionname hardcoded in the c#-designer-code.
Is there really now way, to set the project-connectionstring maybe in the global.asax.cs?
Or another way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您可以更改设计器代码以不对连接名称进行硬编码?
为什么不添加一个名为
GetConnectionStringName()
的方法,该方法由设计器调用并动态选择正确的连接字符串?Perhaps you could change the designer code to not hard code the connection name?
Why not add a method somewhere called
GetConnectionStringName()
which is called by the designer and will dynamically pick the correct connection string?我只是编辑 C# 设计器代码并将其替换为对配置管理器连接字符串引用的引用(或任何能让您满意的内容)。它是自动生成的,这并不意味着您无法编辑它。
I just edit the C#-designer-code and replace it with a reference to the configuration manager connection string reference (or whatever floats your boat). It's generated automatically, that doesn't mean you can't edit it.
@猎人
不清楚,你的意思是。我们使用上下文菜单“Add->Class”在 App_Data-Folder 中创建一个数据集类
@drachenstern
我知道,我可以编辑设计的代码。创建网页的不仅仅是我。每次数据集布局发生变化时,代码都必须再次编辑。这是没有选择的
@Nathan Taylor
这就是设计师创建的代码中的全部内容。我不知道何时访问代码并打开连接。
@Hunter
Not shure, what you mean. we create a Dataset-class in the App_Data-Folder with contextmenu 'Add->Class'
@drachenstern
I know, I could edit the designed code. That's not only me, who create webpages. And everytime something changed in the dataset-layout the code has to edit again. That's no option
@Nathan Taylor
That's all in the designer-created code. I don't know, when the code is accessed and the connection will opened.