App.config似乎被忽略 [英] App.config seems to be ignored

查看:101
本文介绍了App.config似乎被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为重构操作的结果,我有了这个类库. 我添加了一个App.config文件,并添加了以下内容:

I've this Class Library, as a result of a refactor action. I added an App.config file and added something like this:

<configuration>
    <connectionStrings>
        <add name="MyDatabase" connectionString="Data Source=server;Initial Catalog=database;User ID=userid;Password=password" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

但是当我运行应用程序时,调试得知我这是完全被忽略的.立即窗口告诉我:

But when I run the application, debugging learns me this is totally ignored. The immediate window tells me:

ConfigurationManager.ConnectionStrings[0]
                 {data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true}
    base {System.Configuration.ConfigurationElement}: {data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true}
    ConnectionString: "data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
    Key: "LocalSqlServer"
    Name: "LocalSqlServer"
    Properties: {System.Configuration.ConfigurationPropertyCollection}
    ProviderName: "System.Data.SqlClient"

我已经在bin目录中检查了生成的配置文件,其内容与App.config相同.

I've checked generated config file in the bin directory and its contents are identical to the App.config.

我尝试使用以下方法读取App.config:

I try to read the App.config using:

ConfigurationManager.ConnectionStrings[Constants.Connections.DevConnection].ConnectionString

我不会说什么与众不同,但是出了什么问题?

Nothing out of the ordinary I'd say, but what is going wrong?

推荐答案

此connectionString应该位于您正在运行的exe的相应app.config中.

This connectionString should be in the corresponding app.config of the exe that you are running.

这篇关于App.config似乎被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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