Change connectionstring Typed dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've noticed that if I change my connectionstring in the app.config file,
this isn't enough, a second change in the Global.System.Configuration is
necesary!!!

This means that after deployment and if the SQL server is changed, changing
the code is necesary, ..............?.??

can I prevent this?? HOW???

Thx
 
When you deploy the properly configured app.config (or better,
ASSEMBLYNAME.config) is enough.
When developing, though, the correct way is to change the value in
Project/Settings configuration.
 
You can handle the SettingsLoaded event to set the connection string setting
at runtime
void Settings_SettingsLoaded(object sender, SettingsLoadedEventArgs e)
{
this["ConnectionString"] = GetConnectionString();
}
 
To make the dataset designer happy...

--
Sheng Jiang
Microsoft MVP in VC++
Miha Markic said:
What's the point of settings then :-)

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Sheng Jiang said:
You can handle the SettingsLoaded event to set the connection string
setting
at runtime
void Settings_SettingsLoaded(object sender, SettingsLoadedEventArgs e)
{
this["ConnectionString"] = GetConnectionString();
}
 
My development team faced this problem in the last week when we were developing some distributed system.

One choice your have is to:

1 - Eliminate the connectionstring from "Settings" of the typed datasets;
2 - Add the System.Configuration reference to the typed dataset project
3 - Go to each typed dataset Designer.vb file and REPLACE the statement:
"Me._connection.ConnectionString = Global..."
for this one:

Me._connection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("CONNECTION")"

4 - Now your datasets should look for this tag, in the app.config XML file.
5 - If you don't provide the DAL.appconfig.xml file, the typed datasets will look for the Application.appconfig.xml and ... in this XML file you must add the tag:
....
</configSections>
<appSettings>
<add key ="CONNECTION" value ="connection string comes here"/>
</appSettings>
<connectionStrings>
....
See that it comes between configsections and appSettings.

6 - Now if you have the appconfig.xml for the application, you can benefit from taking the connectionstring from this file, instead of having it compiled into the DAL.dll. You can change the connection string in the xml file and see the changes in the connection.

For now, this is the only solution we have achieved for this problem.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Back
Top