.NET 2.0 App.Config 连接字符串包括不需要的 SQLExpress 默认值 [英] .NET 2.0 App.Config connection strings includes unwanted SQLExpress default

查看:17
本文介绍了.NET 2.0 App.Config 连接字符串包括不需要的 SQLExpress 默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .NET 2.0 项目的 app.config 文件中使用 connectionStrings 部分.config 部分包含我定义的两个连接字符串.

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 个条目是到 SQLExpress 的连接

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 中,它也会被包含在内,我该如何摆脱它?此代码将在我无法访问的台式机上运行 - 那么如何防止更多本地连接在运行时随机出现?我看不到连接上的任何属性表明它与我定义的两个属性有任何不同.

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>

作为一般规则,具有 元素(例如 appSettingsconnectionStrings 和提供程序配置部分)还有一个 元素,如果您不想从更高级别的 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 连接字符串包括不需要的 SQLExpress 默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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