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
Solved

Required multiple database support for windows forms application

Posted on 2009-04-07
11
335 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

861 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