none
Extra entry in connection strings section of App.config RRS feed

  • Question

  • I've used simple code to iterate thru all connection strings in App.config file:

    var connStrings = ConfigurationManager.ConnectionStrings;
    int i = 0;
    foreach (var connString in connStrings)
    {
        i++;
        var connStrSet = (ConnectionStringSettings)connString;
        Console.WriteLine(i.ToString() + ". " + connStrSet.Name);
        Console.WriteLine("\t" + connStrSet.ConnectionString);
    }

    But I wondered when I saw extra connection string entry which did not exist in App.config:

    1. LocalSqlServer
            data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

    Where did it come from? :)


    There is no knowledge that is not power.

    Saturday, August 15, 2015 6:05 PM

Answers

  • Hi John,

    1. LocalSqlServer
            data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

    >>Where did it come from?

    Which defines default connection string for ASP.NET database. If you really don't need it for your application, you can either edit machine.config file (not recommended) or clear connection strings before adding yours:

    <connectionStrings>
        <clear />
        <add name="MyContext" 
             connectionString="data ource=(LocalDb)\v11.0;AttachDbFilenameAttachDBFilename=|DataDirectory|aspnetdb.mdf;Integrated Security=True" 
             providerName="System.Data.SqlClient" />
    </connectionStrings>

    Best regards,

    Kristin



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Monday, August 17, 2015 3:06 AM
    • Marked as answer by JohnyL Tuesday, August 18, 2015 4:08 PM
    Monday, August 17, 2015 3:05 AM

All replies

  • Hi John,

    1. LocalSqlServer
            data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

    >>Where did it come from?

    Which defines default connection string for ASP.NET database. If you really don't need it for your application, you can either edit machine.config file (not recommended) or clear connection strings before adding yours:

    <connectionStrings>
        <clear />
        <add name="MyContext" 
             connectionString="data ource=(LocalDb)\v11.0;AttachDbFilenameAttachDBFilename=|DataDirectory|aspnetdb.mdf;Integrated Security=True" 
             providerName="System.Data.SqlClient" />
    </connectionStrings>

    Best regards,

    Kristin



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Monday, August 17, 2015 3:06 AM
    • Marked as answer by JohnyL Tuesday, August 18, 2015 4:08 PM
    Monday, August 17, 2015 3:05 AM
  • @Kristin

    Thanks a lot! It works. I totally forgot about machine.config. :)


    There is no knowledge that is not power.

    Tuesday, August 18, 2015 4:08 PM