none
ConfigurationManager.ConnectionStrings having extra connection setting RRS feed

  • Question

  •  

    Hi there,

     

    I noticed that ConfigurationManager.ConnectionStrings contains an extra connection setting having the name "LocalSqlServer". How can I remove this extra setting from the ConfigurationManager.ConnectionStrings collection? Thanks in advance.

     

    Regards,

    Saturday, October 6, 2007 8:35 AM

Answers

  • Finally, problem solved. I just removed LocalSqlServer in app.config and add a new connection string by the name "LocalSqlServer".

     

    <configuration>

    <configSections>

    </configSections>

    <connectionStrings>

    <remove name="LocalSqlServer"/>

    <add name="LocalSqlServer"

    connectionString="Data Source=127.0.0.1;Initial Catalog=JESite;User ID=sa;Password=password"

    providerName="System.Data.SqlClient" />

    </connectionStrings>

    </configuration>

    Tuesday, October 9, 2007 10:05 AM

All replies

  • The LocalSqlServer is most likely defined in machine.config. Why do you want to remove it?

     

    Best regards,

    Johan Stenberg

    Saturday, October 6, 2007 11:05 PM
  • LocalSqlServer is the connection string needed to use ASPNETDB to configure application services, you code will not run with the Web Admin tool without that connection string.  So you need to find out its use in WCF before you remove it, the link below shows how it is used to configure Asp.net memebership.

     

    <configuration>

     

        <connectionStrings>

            <remove name=”LocalSqlServer”/>

            <add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=appservicesdb;Integrated Security=True" providerName="System.Data.SqlClient"/>

        </connectionStrings>

     

    </configuration>


    http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

     

    Sunday, October 7, 2007 6:47 PM
  • Actually, I intended to translate the xml membership configuration into codes. In other words:

     

    <membership defaultProvider="JESiteSqlProvider" userIsOnlineTimeWindow="20">

    <providers>

    <remove name="AspNetSqlProvider" />

    <add name="JESiteSqlProvider"

    type="System.Web.Security.SqlMembershipProvider"

    connectionStringName="Com.JESite.Properties.Settings.JESiteConnectionString"

    enablePasswordRetrieval="false"

    enablePasswordReset="true"

    requiresQuestionAndAnswer="false"

    minRequiredPasswordLength="3"

    minRequiredNonalphanumericCharacters="0"

    passwordFormat="Hashed"

    applicationName="JESite" />

    </providers>

    </membership>

     

    into....

     

    [TestFixtureSetUp]

    public void FixtureSetUp()

    {

    string m_sqlConnectionString = "Com.JESite.Properties.Settings.JESiteConnectionString";

     

    Util.RemoveProvider(Membership.Providers, "AspNetSqlMembershipProvider");

     

    SqlMembershipProvider testProvider = new SqlMembershipProvider();

     

    NameValueCollection config = new NameValueCollection();

    config.Add("connectionStringName", m_sqlConnectionString);

    config.Add("applicationName", "UC_User");

    config.Add("enablePasswordRetrieval", "false");

    config.Add("enablePasswordReset", "true");

    config.Add("requiresQuestionAndAnswer", "false");

    config.Add("minRequiredPasswordLength", "3");

    config.Add("minRequiredNonalphanumericCharacters", "0");

    config.Add("requiresUniqueEmail", "true");

    config.Add("passwordFormat", "Hashed");

     

    foreach (ConnectionStringSettings connectionString in ConfigurationManager.ConnectionStrings)

    {

    Console.WriteLine("Connection Name={0}", connectionString.Name);

    Console.WriteLine("Connection String={0}", connectionString.ConnectionString);

    }

     

    testProvider.Initialize("UC_User", config);

    Assert.IsTrue(testProvider.EnablePasswordRetrieval == false);

    Assert.IsTrue(testProvider.RequiresQuestionAndAnswer == false);

    Assert.IsTrue(testProvider.MinRequiredPasswordLength == 3);

    Assert.IsTrue(testProvider.MinRequiredNonAlphanumericCharacters == 0);

     

    Util.InjectProvider(Membership.Providers, testProvider);

     

    Assert.AreEqual(Membership.Providers.Count, 1);

    Assert.Contains(testProvider, Membership.Providers);

     

    foreach(MembershipProvider provider in Membership.Providers)

    Console.WriteLine("Provider Name={0}", provider.Name);

    }

     

    However, when I ran NUnit on my test fixture, I came across this error:

    Com.JESite.Test.UC_User.TestRegisterUser : System.Web.HttpException : Unable to connect to SQL Server database.
      ----> System.Data.SqlClient.SqlException : An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

     

    My Console Output:

    Connection Name=LocalSqlServer

    Connection String=data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet.db.mdf;User Instance=true

    Connection Name=Com.JESite.Properties.Settings.JESiteConnectionString

    Connection String=Data Source=127.0.0.1;Initial Catalog=JESite;User ID=sa;Password=password

    Provider Name=UC_User

     

    I concluded that Membership is using connection name "LocalSqlServer" internally even though I tried to specify otherwise in code. I know that this isn't the approriate or correct way to use the Membership class.

     

    The reason why I am doing this is because I wanted to explore the possibility of using Membership in a non web based environment. However, this has led to me think otherwise.

     

    Question: How can I correctly specify the connetion for testProvider to use?

    Monday, October 8, 2007 6:31 AM
  • (I concluded that Membership is using connection name "LocalSqlServer" internally even though I tried to specify otherwise in code. I know that this isn't the approriate or correct way to use the Membership class.)

     

     

    Actually that is what I told you in my posting that you are using an application service created by the Asp.net team which comes with a default required connection string.  A test provider you have to create your own database and objects.

     

     

    Monday, October 8, 2007 11:05 PM
  • Finally, problem solved. I just removed LocalSqlServer in app.config and add a new connection string by the name "LocalSqlServer".

     

    <configuration>

    <configSections>

    </configSections>

    <connectionStrings>

    <remove name="LocalSqlServer"/>

    <add name="LocalSqlServer"

    connectionString="Data Source=127.0.0.1;Initial Catalog=JESite;User ID=sa;Password=password"

    providerName="System.Data.SqlClient" />

    </connectionStrings>

    </configuration>

    Tuesday, October 9, 2007 10:05 AM
  • That is the same connection string I gave you when I joined the thread you just added the loop back IP address.

    Tuesday, October 9, 2007 1:22 PM