Required multiple database support for windows forms application

I have a application in .net2.0 (WinForm). This application should support any database without code change. I just need to change connection string . How can i achieve this functionality.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

spacerat60Connect With a Mentor Commented:
Attached a code snippet, i think this is what you are asking for
// If on the fly you want to change the connection string just have a method which would implement something line this
private Connection connect(String database, String table, String username, String password)
private string connectionString = @"Initial Catalog="+database+";" +
     @"Data Source="+table+";" +
     @"User ID="+username+";" +
SqlConnection connection = new SqlConnection(connectionString);
return connection;
// Execute commands...
    SqlCommand command = new SqlCommand("SELECT * from Itable", connection);
// also make sure to remember to close the connection when you'r done

Open in new window

Consider using NHibernate ( Hibernate takes care of the communication to the databaes (whatever kind of DB) and you business objects.
Database Factory using C# Generics

Implementing a Database Factory Pattern in C# ASP .NET
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Keep in mind that your SQL syntax will have to avoid all propriety extensions so they work on all servers.
vrittiAuthor Commented:
what is propriety extensions, please let me know
rseabirdConnect With a Mentor Commented:
If you don't want to create for each database a different SQL syntax, you propably do the best to use NHibernate. Unfortunately, it has a bit of a high learning curve. But some of my collegues are using it and they are very happy with it. NHybernate makes use of so called mapping files, these you need to create so NHibernate know what is what in the database and application. NHibernate takes care of creating insert, delete, updates etc scripts. And they are of high quality (performance is great).
oobaylyConnect With a Mentor Commented:
By propriety extensions, I mean how different companies have added their own functions and syntax to the standard sql syntax.

For example, this is how you limit the number of results using different servers.
vrittiAuthor Commented:
I know that NHibernate is the good solution but I don't know how to use it and  we don't have so much tim e for learn NHibernate so please if you have some other solution, please let me know
DhaestConnect With a Mentor Commented:
Did you check the Database Factory using C# Generics

Implementing a Database Factory Pattern in C# ASP .NET
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.