简体   繁体   English

为什么connectionstring的配置为只读?

[英]Why is the configuration of connectionstring readonly?

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. 首先:我有一个Web(客户内部网,仅供内部使用),用户可以在其中决定,显示女巫项目。 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. 我不能使用不同的连接字符串名称,因为数据集设计器将硬编码的连接名称存储在c#设计器代码中。

Is there really now way, to set the project-connectionstring maybe in the global.asax.cs? 现在真的有办法在global.asax.cs中设置项目连接字符串吗? Or another way to handle this? 还是另一种处理方式?

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? 为什么不在设计者调用的某个位置添加一个名为GetConnectionStringName()的方法,该方法将动态地选择正确的连接字符串?

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). 我只是编辑C#-designer-code并将其替换为对配置管理器连接字符串引用的引用(或任何使您浮出水面的东西)。 It's generated automatically, that doesn't mean you can't edit it. 它是自动生成的,并不意味着您不能对其进行编辑。

@Hunter Not shure, what you mean. @亨特没什么意思,你的意思。 we create a Dataset-class in the App_Data-Folder with contextmenu 'Add->Class' 我们使用上下文菜单“添加->类”在App_Data-Folder中创建一个数据集类

@drachenstern I know, I could edit the designed code. @drachenstern我知道,我可以编辑设计的代码。 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. @Nathan Taylor这一切都在设计师创建的代码中。 I don't know, when the code is accessed and the connection will opened. 我不知道,何时访问代码并且连接将打开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM