PC Review


Reply
Thread Tools Rate Thread

Change connectionstring Typed dataset

 
 
=?Utf-8?B?THVj?=
Guest
Posts: n/a
 
      29th Jul 2007
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
Luc N
 
Reply With Quote
 
 
 
 
Miha Markic
Guest
Posts: n/a
 
      29th Jul 2007
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/

"Luc" <(E-Mail Removed)> wrote in message
news:65260708-0124-4BAE-AAA3-(E-Mail Removed)...
> 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
> Luc N


 
Reply With Quote
 
Sheng Jiang[MVP]
Guest
Posts: n/a
 
      30th Jul 2007
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++
"Luc" <(E-Mail Removed)> wrote in message
news:65260708-0124-4BAE-AAA3-(E-Mail Removed)...
> 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
> Luc N



 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      30th Jul 2007
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[MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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++


 
Reply With Quote
 
Sheng Jiang[MVP]
Guest
Posts: n/a
 
      30th Jul 2007
To make the dataset designer happy...

--
Sheng Jiang
Microsoft MVP in VC++
"Miha Markic" <miha at rthand com> wrote in message
news:(E-Mail Removed)...
> 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[MVP]" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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++

>



 
Reply With Quote
 
Saulo J. S. Machado
Guest
Posts: n/a
 
      2nd Aug 2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change ConnectionString for DataSet at runtime? wilson Microsoft VB .NET 4 4th Aug 2006 06:59 AM
How to change the ConnectionString for an auto generated typed dataset in a separate dll ??? mateo Microsoft ADO .NET 1 16th Mar 2006 03:13 PM
How to change the ConnectionString for an auto generated typed dataset in a separate dll ??? tanguay.mathieu@gmail.com Microsoft Dot NET Framework 0 16th Mar 2006 12:50 PM
How to change the ConnectionString for an auto generated typed dataset in a separate dll ??? mateo Microsoft Dot NET Framework Forms 0 16th Mar 2006 12:48 PM
How to change the ConnectionString for an auto generated typed dataset in a separate dll ??? mateo Microsoft ASP .NET 0 16th Mar 2006 12:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 PM.