How to : Programmatically change Connection String
I want to change Connection String programmatically:
the key point is to write some code in Settings.cs file.for example I used a Property:
public string RuntimeChangeConnectionString
{
set { this["DataBaseConnectionString"] = value; }
}
and then you can use this property in your code.
Here is my sample to do that.
it will create 2 SQLite file in your “My Documents” but it uses one connection string,you can change the connection string to load different databases.
you need SQLite to run the sample.
you may need these resources too:
Customizing the connection string for TableAdapters
Properties (C# Programming Guide)
Download Sample: C#
leave a comment