none
Connection-String Management RRS feed

  • Question

  •  

    I am using a strongly typed dataset and TableAdapters to communicate with the Database. When i am creating the Dataset, automatically the Connection String will be saved in My.Settings

     

    My problem is, I want to have the Connection-String dynamically. So the application-adminstrator should have the possibility to change the Connection-String. But because the Connection string is read only it's not possibel to save this one in to the Settings File.

     

    What should I do?

     

    Thanks Patrick

    Sunday, May 18, 2008 2:02 PM

Answers

  • I've had issues with this in the past.  When I attempted to put the connection strings in the app.config file, and then point the dataset to that instead of the one in the settings file, this actually works at first, but if you make changes to the database, I had to delete and re-create the dataset.

     

    The connection string you're working with isn't read-only, you can change it by going to the settings of the project.

     

    I ended up just using business objects instead of datasets.  It just gives a lot more flexibility for situations like this (in my opinion).

    Monday, May 19, 2008 1:36 AM
  • The TableAdapter configuration wizard depends on the schema and rights specified in the ConnectionString. One approach you might try (to trick the system) to redirect the connection to another server instance (that has an identical schema and rights signature) is to use an alias. In this case instead of using the hard-coded server instance name, use "Fred" and build an alias to the development database server instance using the SQL Server Configuration Manager utility. This makes the ConnectionString (and the Data Source connection string) look like this:

     

    "Server=Fred; initial catalog=George; integrated security=SSPI..."

     

    When it comes time to switch to another server, simply change the alias and the next time the application starts (and the connection pool is built) the system will address the alternate instance.

     

     

     

    Monday, May 19, 2008 2:22 AM
    Moderator
  • In this case I think I found a better way. I changing the ConnectionString object in the Settings to typeOf string. Then I can change it from the application. It just needs to have the same name as before, when I created the Dataset.

     

    The other way I see would be to change always the connection of the tableAdapter on initializing this one. So I can use a ConnectionStringManager class where I can change the connectionstring from the application and can encrypt passwords.

    I think this is the way I will do it for now.

     

    Patrick

    Monday, May 19, 2008 1:59 PM

All replies

  • I've had issues with this in the past.  When I attempted to put the connection strings in the app.config file, and then point the dataset to that instead of the one in the settings file, this actually works at first, but if you make changes to the database, I had to delete and re-create the dataset.

     

    The connection string you're working with isn't read-only, you can change it by going to the settings of the project.

     

    I ended up just using business objects instead of datasets.  It just gives a lot more flexibility for situations like this (in my opinion).

    Monday, May 19, 2008 1:36 AM
  • The TableAdapter configuration wizard depends on the schema and rights specified in the ConnectionString. One approach you might try (to trick the system) to redirect the connection to another server instance (that has an identical schema and rights signature) is to use an alias. In this case instead of using the hard-coded server instance name, use "Fred" and build an alias to the development database server instance using the SQL Server Configuration Manager utility. This makes the ConnectionString (and the Data Source connection string) look like this:

     

    "Server=Fred; initial catalog=George; integrated security=SSPI..."

     

    When it comes time to switch to another server, simply change the alias and the next time the application starts (and the connection pool is built) the system will address the alternate instance.

     

     

     

    Monday, May 19, 2008 2:22 AM
    Moderator
  • In this case I think I found a better way. I changing the ConnectionString object in the Settings to typeOf string. Then I can change it from the application. It just needs to have the same name as before, when I created the Dataset.

     

    The other way I see would be to change always the connection of the tableAdapter on initializing this one. So I can use a ConnectionStringManager class where I can change the connectionstring from the application and can encrypt passwords.

    I think this is the way I will do it for now.

     

    Patrick

    Monday, May 19, 2008 1:59 PM