Solved

Required multiple database support for windows forms application

Posted on 2009-04-07
11
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

739 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