Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigurationManager.ConnectionStrings returns extra connection string from machine.config [duplicate]

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

like image 284
sal el Avatar asked Feb 22 '13 02:02

sal el


1 Answers

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>
like image 119
Zahir Ally Avatar answered Oct 21 '22 08:10

Zahir Ally