Solved

Required multiple database support for windows forms application

Posted on 2009-04-07
11
333 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
ID: 24087142
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
ID: 24087156
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
ID: 24087191
Keep in mind that your SQL syntax will have to avoid all propriety extensions so they work on all servers.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Accepted Solution

by:
spacerat60 earned 125 total points
ID: 24087234
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
 

Author Comment

by:vritti
ID: 24087254
what is propriety extensions, please let me know
0
 
LVL 8

Assisted Solution

by:rseabird
rseabird earned 125 total points
ID: 24087378
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
ID: 24087552
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
ID: 24087601
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
ID: 24135356
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

816 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

9 Experts available now in Live!

Get 1:1 Help Now