App.config - LocalSqlServer connection string

See code below:

Public Shared Sub SyncConnectionStrings() Dim strCon As String Dim tyDatabase As typeDatabase Dim boolConfigChanged As Boolean 'Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) Dim strConnectionString As ConnectionStringSettings For Each strConnectionString In ConfigurationManager.ConnectionStrings 'More code here, but irrelevant for this question. Next End Sub 

Encodes all connection strings in the app.config file. There are three connection strings in app.config , but four connection strings are found. Where is: LocalSqlServer (this is ConfigurationManager.ConnectionStrings.Name ) defined?

+4
source share
2 answers

It is defined in the global Machine.config file located in

 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\CONFIG". 

It is generated during the installation of NET.Framework and is required by tools that work with ASPNETDB

If you do not need it, you can try adding this to your app.config

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

and

 <connectionStrings> <remove name="LocalSqlServer" /> 

but I really suggest not changing anything in Machine.Config if you don't know the side effects.

+8
source

In your Machine.config, it is possible to have more than just LocalSqlServer. For example, I just ran the application on a computer with MySql connection in Machine.config

You can use the ElementInformation property for ConnectionStringSetting to determine where it came from:

  foreach (ConnectionStringSettings c in ConfigurationManager.ConnectionStrings) { ElementInformation elementInfo = c.ElementInformation; String source = elementInfo.Source; if (source == null) { //Machine.config } else { Console.WriteLine("{0} {1} {2}", c.Name, elementInfo.Source, c.ConnectionString); } } 
+2
source

Source: https://habr.com/ru/post/1479512/


All Articles