Groups | Blog | Home
all groups > dotnet ado.net > july 2007 >

dotnet ado.net : Change connectionstring Typed dataset


Luc
7/29/2007 3:38:02 AM
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

--
Best regards
Miha Markic
7/29/2007 8:56:19 PM
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.

--
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/

[quoted text, click to view]
Sheng Jiang[MVP]
7/30/2007 2:17:57 PM
You can handle the SettingsLoaded event to set the connection string setting
at runtime
void Settings_SettingsLoaded(object sender, SettingsLoadedEventArgs e)
{
this["ConnectionString"] = GetConnectionString();
}

--
Sheng Jiang
Microsoft MVP in VC++
[quoted text, click to view]

Sheng Jiang[MVP]
7/30/2007 4:23:18 PM
To make the dataset designer happy...

--
Sheng Jiang
Microsoft MVP in VC++
[quoted text, click to view]

Miha Markic
7/30/2007 10:29:34 PM
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/

[quoted text, click to view]
Saulo J. S. Machado
8/2/2007 5:40:28 AM
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
AddThis Social Bookmark Button