CodeSmith Community
Your Code. Your Way. Faster!

Changing the connectionstring at runtime

Latest post 04-02-2006 6:45 PM by Robert Hinojosa. 6 replies.
  • 03-09-2006 5:53 AM

    • asegela
    • Top 500 Contributor
    • Joined on 03-09-2006
    • Posts 11
    • Points 260

    Changing the connectionstring at runtime

    Hello to the community,

    I would like to change the connection string to another database at runtime. I did different aproaches to code this but finally failed to do so. I have a WinForm front end with a list of different database servers and database names and have to connect to them. Currently the only way to change the connection string is to edit the configuration file but this is not an option. Has anyone an idea of how to solve this problem?

    my configuration:

    - Visual Studio 2005

    - NetTiers-version: nettiers2-CTP-20060301

    - SQL-Server 2000

    Thanks for help.

    • Post Points: 35
  • 03-09-2006 6:38 AM In reply to

    Re: Changing the connectionstring at runtime

    In the DataAccesslayer there is a class TransactionManager.cs

    in this class is a declaration

    private string connectionString;

    this is the value you need to change, unfortunatly as I found you need to now hack the code around a bit, but it depends on how you want to do the next step.

    If you want to sort the connection string in the DataAccessLayer settings or registry then you can specify this at the declaration point above this will always be use then and override what is in the app.config file

    else you will ne to create yourself a new class where you can pass you the connection string to from the font end  probably into  a property then you can replace the calls to connectionstring with your new property.

    I can dig out the code of how I did it if you need more info.

    • Post Points: 35
  • 03-09-2006 9:57 AM In reply to

    • asegela
    • Top 500 Contributor
    • Joined on 03-09-2006
    • Posts 11
    • Points 260

    Re: Changing the connectionstring at runtime

    Thanks for the quick reply. I found the TransactionManager and got the connection string. Unfortunately not all functions of the several providers take a TransactionManager as input parameter e.g. GetTotalItems(...). There is no given opportunity to change the connect string permanently. I would appreciate any help from you to solve the problem. To post your code would be nice (:-)).

    Thanks in advance.

    • Post Points: 65
  • 03-09-2006 10:50 AM In reply to

    Re: Changing the connectionstring at runtime

    Hi asegela,

    Which version of nettiers are you using. All my DAL functions use transaction manager. I have never come accross Gettotalitems() before.

    I will did out what i did and post it when i get chance, but it may be a while.

    • Post Points: 35
  • 03-09-2006 3:09 PM In reply to

    Re: Changing the connectionstring at runtime


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 5
  • 03-10-2006 5:49 AM In reply to

    • asegela
    • Top 500 Contributor
    • Joined on 03-09-2006
    • Posts 11
    • Points 260

    Re: Changing the connectionstring at runtime

    Hi Justdeserves,

    our development environment is located at a different place, so it took me a while to verify the GetTotalItems(...) function. Each EntityProvider containes such a function which takes a parameter as input to define a "Where" clause and gives back the total number of affected records. Inconsistently this is the only function which does not take a TransactionManager as input parameter and due to Murphy's law we have to use it permanently. Anyway such is life. There is an other threat in the forum covering the same connection string subject. Goofsr has stated that this will be worked over and adapted to meet this requirement. Hopefully it will not take that long. However, I am still interested in your code. So if you dont mind, post it as soon as you can.

    Thanks again.

    • Post Points: 35
  • 04-02-2006 6:45 PM In reply to

    Re: Changing the connectionstring at runtime


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 5
Page 1 of 1 (7 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems