2

I am maintaining a site that was not built by me in ASP.NET.
it is built in C#.NET

the site access a Database using a DLL called MegaTecDAL.dll
(Note: i dont have the code for this dll, only the dll and PDB)

Recently, we need to move the site to another server with another database, and therefore need to change the connection string for the database. which i thought should be pretty Easy!
i didn't find the connection string in the web.config or anywhere so,

I decompiled the Data Access Layer MegaTecDAL.DLL to get where the connection string is read from, and found the following (Notice: getzConnectionString)

namespace MegaTecDal.Properties
{
  [CompilerGenerated]
  [GeneratedCode("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
  internal sealed class Settings : ApplicationSettingsBase
  {
    private static Settings defaultInstance = (Settings) SettingsBase.Synchronized((SettingsBase) new Settings());

    public static Settings Default
    {
      get
      {
        Settings settings = Settings.defaultInstance;
        return settings;
      }
    }

    [DefaultSettingValue("Data Source=old.server.address.com;Initial Catalog=getz;User ID=aUserName;Password=StrongPassword")]
    [ApplicationScopedSetting]
    [SpecialSetting(SpecialSetting.ConnectionString)]
    [DebuggerNonUserCode]
    public string getzConnectionString
    {
      get
      {
        return (string) this["getzConnectionString"];
      }
    }

    static Settings()
    {
    }
  }
}

I Realize, that the connection string is taken from the Default.
but i cant seem to find how to specify a new Value.

I Tried:

adding to the web.config

<connectionStrings>
    <add name="getzConnectionString" connectionString="Data Source=new.server.com;Initial Catalog=getz;User ID=aUserName;Password=StrongPassword" providerName="System.Data.SqlClient" />
</connectionStrings>

also tried adding to web.config

<appSettings>
    <add key="getzConnectionString" value="Data Source=new.server.com;Initial Catalog=getz;User ID=aUserName;Password=StrongPassword"/>
</appSettings>

tried creating a file named MegaTecDAL.dll.config with the above sections and put it in the BIN/App_Data/App_Code & root folders but still, default connection string is called.

also tried adding Section group and section per http://msdn.microsoft.com/en-us/library/8eyb2ct1.aspx

Anywhere i put it it does not do it.

2 Answers 2

4

I think you need to include the namespace of the ConnectionString you want to configure:

<connectionStrings>
  <add name="MegaTecDal.Properties.Settings.getzConnectionString" 
       connectionString="yourNewConnectionString"
       providerName="System.Data.SqlClient"  />
</connectionStrings>
Sign up to request clarification or add additional context in comments.

Comments

0
<connectionStrings>
  <add 
      name="getzConnectionString" 
      connectionString="Data Source=serverName;Initial 
      Catalog=getz;Persist Security Info=True;User 
      ID=userName;Password=password"
     providerName="System.Data.SqlClient"/>
</connectionStrings>

This might helps you. Try to add this. for more details check this link http://msdn.microsoft.com/en-us/library/ms178411%28v=vs.100%29.aspx

4 Comments

i already did that in web.config and in MegaTecDAL.dll.config but not working
no, the site is connecting to the default database in the old server
I think you are reading it by wrong way. check my edited code
Thanks for your help, but i aint using ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString.ToString(); because it is not my code that reading the Connection... i just needed to write the setting correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.