Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Questions on OleDBConnection vs SQLConnection
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00686643
Message ID:
00686680
Views:
36
One generic approach is to use the interfaces for the ADO.NET objects. If you code against the various interfaces (IDbConnection, IDbDataAdapter, IDbCommand, etc) then your program could decide at runtime which set of database classes to use.
Consider the following:

IDbConnection GetConnection(string ConnectString) {

switch( SomeConfigurationVariable ) {
case ConnectionType.OleDb:
return new OleDb.OleDbConnection(ConnectString);

case ConnectionType.Odbc:
return new Odbc.OdbcConnection(ConnectString);

case ConnectionType.Sql:
return new SqlClient.SqlConnection(ConnectString);
}
}

This will allow you to write some fairly generic code that will work
with any database and will also allow your program to take advantage of
the performance boost you gain when using the SqlClient objects with SQL
server. Generally you will need a function, similar to the one above that can return an IDbConnection and another function that can
return an IDbDataAdapter.

>Hi, folks...
>
>Two questions...
>
>First, we recently learned that our app *may* need to support either SQL Server or Oracle. Up to this point, we've been using SQLCONNECTION, SQLADAPTER, and SQLCOMMAND in our data access component. Obviously (or at least I believe obviously), we could be more generic and use OLEDBCONNECTION, OLEDBADAPTER, and OLEDBCOMMAND instead. However, I've heard (2nd hand) that those commands are slower than the SQL command counterparts. Is this true?
>
>If it is, then I have a 2nd question...we considered have a general CONNECTION method (and a general ADAPTER method and a general DBCOMMAND function), where we'd issue either a SQL... command or an OLEDB...command. However, it also occured to me that since these 'generic' functions need to return something (a connection handle, a reference to an adapter) that would be stronly typed, we'd need to go a step further...and that seems more complicated than necessary.
>
>So has anyone tried to write generic methods to deal with this type of access (SQL vs non-SQL Server), and what approaches have they tried? (And if anyone has any URLs that cover this type of thing, that would also help)
>
>Thanks,
>Kevin
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform