问题
I'm writing a windows service and I need the list of all connection strings defined in App.config.
I Used System.Configuration.ConfigurationManager.ConnectionStrings to get all connections.
it always return this extra connection:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
that I think is added in machine.config.
my App.config is:
<add name="AvmPortalConnectionString"
connectionString="Data Source=.;Initial Catalog=AvmPortal;Integrated Security=True"
providerName="System.Data.SqlClient" />
Is there anyway that I can get only connection Strings defined in App.config(not the one in machine.config)
I can remove this, but I wonder if there is a cleaner way!
Thanks
回答1:
Try adding a clear before the add:
<connectionStrings>
<clear />
<add name="AvmPortalConnectionString"
connectionString="Data Source=.;Initial Catalog=AvmPortal;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
来源:https://stackoverflow.com/questions/15015892/configurationmanager-connectionstrings-returns-extra-connection-string-from-mach