none
How to set table adapter manager connection string at run time and return to this setting the next time the application runs RRS feed

  • Question

  • I have an application written in C# using VS 2008 that is meant to be installed on any machine and access an MS SQL db either on the host machine or a remote server either in an intranet or external.

    Since the db host location is unknown at build time, the db connection string must be set at run time, the change saved and used the next

    time the application is run.

    I would like to do this by changing the table adapter manager connection string so as not to have to change all the table adapter  connection strings.

    I have the user run a set up form and build the new connection string. It parses fine and is then set as the new connection string. I.E.

    this.tableAdapterManager.Connection.ConnectionString = newConnection;

    Displaying this.tableAdapterManager.Connection.ConnectionString.tostring in a message box shows the new connection in effect.

    Checking the connection state shows it to be open.

    However, after opening the connection and populating grids, the new connection was not used. The connection used the original connection string.

    I have the modifier property all adapters set to public.

    I have created a new setting for a blank connection string in an attempt to set the scope to user which would allow dynamic changes but the setting defaults to application level instead of user.

    I can read the build time connection string from the app.config file but can not seem to overide it or write a new one suspecting that this a a read only value.

    Thanks,

    Jim


    Thursday, June 10, 2010 5:45 PM

Answers