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

后端 未结 7 1756
孤街浪徒
孤街浪徒 2021-02-20 01:19

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 data

7条回答
  •  走了就别回头了
    2021-02-20 02:15

    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?)

提交回复
热议问题