问题描述
我在.NET 2.0项目中使用内的app.config文件中的的ConnectionStrings
部分。在配置部分包含我已经定义了两个连接字符串。
I'm using a connectionStrings
section within an app.config file in a .NET 2.0 project. The config section contains two connection strings I have defined.
当我取回 ConnectionStringSettingsCollection
它有3计数第0项是SQLEx preSS
When I retrieve the ConnectionStringSettingsCollection
it has a count of 3. The 0th entry is a connection to SQLExpress
Name: LocalSqlServer,
ConnectionString: data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
为什么被列入这方面,即使它不是在我的app.config,以及我怎样才能摆脱它?这code将在台式机,我都进不去运行 - 这样我怎么能prevent从随机显示在运行时更多的本地连接?我看不出在连接上的任何属性,表明它有什么不同,从我定义的两个。
Why is this connection being included even though it's not in my app.config, and how can I get rid of it? This code will be running on desktop machines that I have no access to - so how can I prevent any more local connections from randomly showing up at runtime? I can't see any properties on the connection that indicate it's any different from the two I defined.
推荐答案
它在machine.config中定义。为了摆脱它,使用:
It's defined in machine.config. To get rid of it, use:
<connectionStrings>
<clear/>
<add ... >
</connectionStrings>
作为一般规则,部分具有&LT;添加&gt;
和&LT;删除&GT;
元素(例如的appSettings
,的ConnectionStrings
和提供配置部分)也有一个&LT;清&GT;
元素,你可以使用,如果你不想继承一个更高级别的Web.config或machine.config文件的元素。
As a general rule, sections that have <add>
and <remove>
elements (e.g. appSettings
, connectionStrings
and the provider configuration sections) also have a <clear>
element, which you can use if you don't want to inherit elements from a higher level web.config or machine.config file.
这篇关于.NET 2.0的app.config连接字符串包含多余的SQLEx preSS默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!