Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing dataset connection string at runtime

I have a c# generated dataset. How can I change the connection string so I can use the dataset with another (identically structured yet differently populated) database? This has to occur at runtime as I do not know the server or database name at compile time. I am using c# 2.0.

like image 714
DanDan Avatar asked Aug 13 '10 14:08

DanDan


People also ask

How to change dataset connection string in c#?

Right click your project > Properties > Settings. You can then change connection string. For best results, you can first open file app. config (for non-web projects) and modify your connection string.

How do I update my connection string?

In the Properties window, expand the Connection node. To quickly modify the connection string, edit the ConnectionString property, or click the down arrow on the Connection property and choose New Connection.

How to create dynamic connection string in VB net?

Start by creating a new project in Visual Studio 2010, for C#. Name the project ConnectionStringSample . Then we will add the datasource to the application. For our example application, we will work with NorthWind sample database for SQL Server, but for any other database the procedure will be the same.


1 Answers

You can modify a single instance of the table adapter.

_myAdapter.Connection.ConnectionString = connectionString;
like image 168
Quentamia Avatar answered Sep 21 '22 21:09

Quentamia