Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to set strongly typed dataset connection string at runtime?

My Windows Forms application uses a strongly typed dataset created using the designer in Visual Studio. At runtime I would like to be able to select either the live or test database.

What is the best way to programmatically set the connection string for the dataset at runtime?

like image 279
wethercotes Avatar asked Mar 29 '09 22:03

wethercotes


1 Answers

It's a pain to edit the designer file.

I created a Settings entry under "User' called 'ConnectionString', which makes Visual Studio create an application string 'Connection String1' when you add a strongly typed data set.

So, I just replace all 'ConnectionString1' with 'ConnectionString' in the dataset designer file, and that will allow you to use a 'User' string setting to load your connection string at runtime.

IMHO it's a shortcoming allowing users to modify connection strings at runtime. (Anyone listening in Redmond?)

like image 193
Walter Knopf Avatar answered Sep 21 '22 14:09

Walter Knopf