locked
Run Time APP DB Changing RRS feed

  • Question

  • Hi To all..

    I´m having a trouble when i'm trying to change de db...

    it's a little coinfusing explain this but here it goes

     

    i'm developing an App, this one needs to change to multiple server and Db, i have al ready have the Xml config file to do this change and a small line of code, but i don't know if is ok this or it has anoher way to make a little app, who changes the connection string, in run time...it' will be great any help

    Monday, June 25, 2007 4:02 PM

Answers

  • yup i ready know that but too i know you can change the connection strings from the path...and thats the thing i want to do...load the xml config, where the connection string of the db is, on it a little form to rewrite it just that fiel example here it goes a code:

    the hightlited text is the one i want to change in a little form, once donig this i can search any db...!!!

     

    thaks a lot for you help

     

    <?xml version="1.0"?>

    <configuration>

    <appSettings/>

    <connectionStrings>

    <add name="logIn" connectionString="Data Source=(local);Initial Catalog=DB1;Persist Security Info=True;User ID=sa;Password=123"

    providerName="System.Data.SqlClient" />

    <add name="Cnn1" connectionString="Data Source=(local);Initial Catalog=DB2;Persist Security Info=True;User ID=sa;Password=123"

    providerName="System.Data.SqlClient" />

    <add name="Cnn2" connectionString="Data Source=(local);Initial Catalog=DB3;Persist Security Info=True;User ID=sa;Password=123"

    providerName="System.Data.SqlClient" />

    </connectionStrings>

    <system.web>

    <compilation debug="true"/>

    <authentication mode="Forms">

    <forms loginUrl="Default.aspx" defaultUrl="Protected/Main.aspx">

    </forms>

    </authentication>

    </system.web>

    </configuration>

    Wednesday, June 27, 2007 5:11 PM
  • Hi,

    For winform application, it calls client setting just as I described in my previous post.

    So I suggest you to define multiple connection strings as choices.

     

    Thanks

    Friday, July 6, 2007 1:40 AM

All replies

  • What exactly are you changing the database for?  Are you doing software load balancing or just accessing different servers for development, staging, production, etc?  If it is the latter, you could use an abstract factory to return the correct connection to the correct environment.  Software load balancing is going to take a bit more work and not something that I have done (the company I work for uses hardware load balancers).
    Monday, June 25, 2007 5:26 PM
  • I'm just wanna manage different enterprises in the same app, and they have their own db, i will put a validation login, and a enterprise selection, that´s why i wanna manage the same structure of my db, example if i have 5 enterprises, i will have 5 DB, with the same structure i'm just wanna change in runtime the selection example in a combobox and i will put manually the name server, user and pwd, this will do if i go wherever out the lan if i have static ip i will put in and i will be able to do it,

    for this i have a little "app.config" file and a some line of codes, but i'm a kindo of stocken!!

    thanks for you interest!

    Tuesday, June 26, 2007 2:01 PM
  • Hi, djmikke

    Application settings in .NET 2.0  has two types, based on scope, i.e. application-scoped settings and user-scoped settings.

    Application-scoped settings provide information associated with the application, so users cannot change them at run time. User-scoped settings can be used for information such as remembering the last position of a form or a font preference. Users can change these values at run time.

     

    For more information, see: “Client Settings FAQ”

    http://blogs.msdn.com/rprabhu/articles/433979.aspx

     

     

    Thanks
    Wednesday, June 27, 2007 9:05 AM
  • yup i ready know that but too i know you can change the connection strings from the path...and thats the thing i want to do...load the xml config, where the connection string of the db is, on it a little form to rewrite it just that fiel example here it goes a code:

    the hightlited text is the one i want to change in a little form, once donig this i can search any db...!!!

     

    thaks a lot for you help

     

    <?xml version="1.0"?>

    <configuration>

    <appSettings/>

    <connectionStrings>

    <add name="logIn" connectionString="Data Source=(local);Initial Catalog=DB1;Persist Security Info=True;User ID=sa;Password=123"

    providerName="System.Data.SqlClient" />

    <add name="Cnn1" connectionString="Data Source=(local);Initial Catalog=DB2;Persist Security Info=True;User ID=sa;Password=123"

    providerName="System.Data.SqlClient" />

    <add name="Cnn2" connectionString="Data Source=(local);Initial Catalog=DB3;Persist Security Info=True;User ID=sa;Password=123"

    providerName="System.Data.SqlClient" />

    </connectionStrings>

    <system.web>

    <compilation debug="true"/>

    <authentication mode="Forms">

    <forms loginUrl="Default.aspx" defaultUrl="Protected/Main.aspx">

    </forms>

    </authentication>

    </system.web>

    </configuration>

    Wednesday, June 27, 2007 5:11 PM
  • Hi, djmikke

    Sorry my taking for granted that you are dev winform application, while you seems to dev ASP.NET one.

    To use multiple connection strings for choosing is a good choice.

    Thanks

    Thursday, June 28, 2007 2:30 AM
  • No i was wrong i haven't tell you what technology i was using...

    but i'm still stocken there....any idea it'll be great.....by the way it are a way to do this in a Winform using C#

    i do not a app.config or smething like that?

    Thursday, July 5, 2007 3:55 PM
  • Hi,

    For winform application, it calls client setting just as I described in my previous post.

    So I suggest you to define multiple connection strings as choices.

     

    Thanks

    Friday, July 6, 2007 1:40 AM