SQL and Database Brand/Provider

N

Nice Chap

My application can use both SQLClient & OleDBClient, how can I write a
common SQL for both the options ? OleDB uses ? as a parameter and SqlClient
expects @Name as the parameter. I don't want to inject literal values into
the Sql. Is there is a way out at all ?
 
W

William Ryan eMVP

This scenario is made to order for a Factory Pattern. basically you can
call your factory and have it build the respective code for you. Yes,
you'll still have to write code to handle both situations, but the only
other solution is to not use the db specific provider which reduces
funcionality and performance. Since OleDb (Access for instance), Oracle and
Sql Server all implement different things, behave differently (ISNull is
totally different in Access - it's a boolean) than SQL Server or Oracle
where it replaces stuff, you are going to have to either write code to take
advnatage of that functionality when it's available as well as when it's
not, or you'll have to forego using it.

A factory lets you do both, and you can share a lot of the methodology, just
branch off when you need to. If you google on ADO.NET Factory Pattern,
there are quite a few examples. You can also try implementing
IDBCOnnection, IDBCommand etc.... but remember, no matter what there's the
tradeoff...if you want to write once and have it run everywhere, you are
going to forego some performance and functionality, if you want the best of
both worlds, you are going ot have to write some extra code.

HTH,

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top