Link to home
Start Free TrialLog in
Avatar of jerra
jerra

asked on

C#, accessing different database types (Oracle, SQL Server, MySQL, ...) How do I use SqlConnection class?

In my C# application users can setup various datasources and connect to them to retrieve data. I have so far used OdbcConnection class but I am switching to SqlConnection class (and relevant family classes)
Now, do I need to load different libraries depending on whether it is a SQL Server or a Oracle DB before instantiating the SqlConnection object? Or is it transparent, .NET will use correct underlying libs based on the ADO connection string?

C# VS2010 Professional
Avatar of hongjun
hongjun
Flag of Singapore image

You need to use the different connection object.
are you using the helper class from microsoft data blocks ?

if so you can only use it for MS Sql.

you need to use different class for different databases.
ASKER CERTIFIED SOLUTION
Avatar of rajaamirapu
rajaamirapu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The connection string specifies a different data provider.  So, at a connection level, it's fairly transparent.  However, you still need whichever library is implicit for the dataprovider.

Beyond that, the dbms functionality available over each connection is different, so at the application level, transparency is not so good.   For example, SQL that works on one dbms may fail or return different results on another.  Generally, you mitigate those differences with a data access layer that has the same contract on all backend platforms.
Avatar of jerra
jerra

ASKER

>However, you still need whichever library is implicit for the dataprovider.
Does .NET take care of which library is used based on the connection string? I'll just create the SqlConnection object and go from there?

At this stage the differences in dbms' isn't a problem because I only need to use basic SELECTs and such. It is the setting up of the connection that I need understand. I have quite a load of refactoring to do and I don't want to cause myself even more work doing something stupid based on my poor knowledge on the subject.