开发者

.NET 2.0 App.Config connection strings includes unwanted SQLExpress default

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.

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

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.


It's defined in machine.config. To get rid of it, use:

<connectionStrings>
    <clear/>
    <add ... >
</connectionStrings>

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜