Solved

Required multiple database support for windows forms application

Posted on 2009-04-07
11
331 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:vritti
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 8

Expert Comment

by:rseabird
Comment Utility
Consider using NHibernate (www.nhibernate.org). Hibernate takes care of the communication to the databaes (whatever kind of DB) and you business objects.
0
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
Database Factory using C# Generics
http://www.codeproject.com/KB/database/DBaseFactGenerics.aspx

Implementing a Database Factory Pattern in C# ASP .NET
http://www.primaryobjects.com/CMS/Article81.aspx
0
 
LVL 15

Expert Comment

by:oobayly
Comment Utility
Keep in mind that your SQL syntax will have to avoid all propriety extensions so they work on all servers.
0
 

Accepted Solution

by:
spacerat60 earned 125 total points
Comment Utility
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+";" +

     @"Password="+password+"";
 

SqlConnection connection = new SqlConnection(connectionString);
 

connection.Open();
 

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

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:vritti
Comment Utility
what is propriety extensions, please let me know
0
 
LVL 8

Assisted Solution

by:rseabird
rseabird earned 125 total points
Comment Utility
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).
0
 
LVL 15

Assisted Solution

by:oobayly
oobayly earned 125 total points
Comment Utility
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.
http://en.wikipedia.org/wiki/Select_(SQL)#Non-standard_syntax
0
 

Author Comment

by:vritti
Comment Utility
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
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 125 total points
Comment Utility
Did you check the Database Factory using C# Generics
http://www.codeproject.com/KB/database/DBaseFactGenerics.aspx

Implementing a Database Factory Pattern in C# ASP .NET
http://www.primaryobjects.com/CMS/Article81.aspx
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now