Iuvo

How to : Programmatically change Connection String

Posted in .NET, C#, Database, SQLite by محمود on April 1, 2009

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:

Connection strings for SQLite

Customizing the connection string for TableAdapters

Properties (C# Programming Guide)

Download Sample: C#

Tagged with: , ,