Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All ,

I am currently using this method to connection SQL SERVER database

C#
String line = sr.ReadToEnd();

                        string connString = ValueCompair.Properties.Resources.ConnectionString.ToString();
                            //@"Server=MDT825;DataBase=Test;User Id=TestUser;Password=TestUser@123;Integrated Security=SSPI";

                        string query = line;

                        SqlConnection conn = new SqlConnection(connString);
                        SqlCommand cmd = new SqlCommand(query, conn);
                        conn.Open();


Here as you see my connection string is dynamic and user can connection either to SQLSERVER OR ORACLE .

My question is Can it run for oracle as well ?
IF not the suggest me common method for below operation which can run for SQLSERVER and ORACLE
1) Connecting database
2) Running Query
Posted

I believe, and I may be wrong, but if you program against the base class of DBConnection then you can code for both Oracle and SQL.

http://msdn.microsoft.com/en-us/library/system.data.common.dbconnection.aspx[^]
 
Share this answer
 
It's always a good idea to encapsulate the database connection object within a singleton class. I don't think that 'SqlConnection' class will work with oracle as well. Even though I'm not quite familiar how it works in C#, I'm pretty sure it's a microsoft specific thing (therefore SQL Server specific). You will need a driver for oracle database connection and a respective class for it.
 
Share this answer
 
v2
I think your best approach might be to use the factory pattern

data layer abstract factory[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900