Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Required multiple database support for windows forms application

Posted on 2009-04-07
11
Medium Priority
?
342 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Accepted Solution

by:
spacerat60 earned 500 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 500 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 500 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

885 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