Hi Mary,
Thank you for clarifying the issue for me.
I had hoped there was a "minimum level" of compatibility between the
providers above the Connection level, that I could program against and
over-ride if need be to use more specific features. For example, I
dont use stored procedures or parameters. So I would think a gneric
Command object and hence a generic DataAdapter, DataReader would be
possible.
But we have to work with what we are given. And I do thank you for
clarifying.
John
On Tue, 08 Feb 2005 14:43:16 -0500, "Mary Chipman [MSFT]"
You can only write generic code that goes against multiple data
providers up to a point -- and that point is Command objects. The
problem is that each provider has its own syntax for handling
parameters, so it ends up being impossible to provide an elegant
solution without writing branching code that is provider-specific. The
reason your old VB6 code worked with DAO/SQL Server is because when
you used DAO with SQL Server, Jet was loaded under the covers and
provided the translation into ODBC-T-SQL for you. So you were going
through multiple layers--DAO-Jet-ODBC-SQL Server, which might have
been fine for a small database with few users, but was inherently
limited and not at all scalable.
--Mary
Thank you Keanen for your response. The MS site says to program
against the IDBConnection, etc. I have no idea how to do that.
What I was hoping was to be able to be able to create a generic object
(e.g. Connection) and then have a routine that would cast it as the
OleDB or SQLDb version based on an application's configuration
parameters. But it seems that System.Data only implements the DataSet
objects and not the provider type...too bad.
Is the following code legal (i.e. putting different Dim statements
within an If-Then-Else clause? (I hope this is not a really stupid
question...but hey, if I dont ask I will never know)
If USE_SQL then
dim conn as New SQLDb.Connection( <some connection string stuff>)
dim cmd as New SQLCommand
dim da as New SQLDataAdapter()
Else
dim conn as New OleDB.Connection(<some connection string stuff>)
dim cmd as New OleDBCommand
dim da as New OleDBDataAdapter()
End If
< work with the above ojects here in a general way>
TIA,
John
On 7 Feb 2005 08:15:17 -0800, "Keanen"
As far as I know, there is no real way to generalize everything except
to create a separate data access layer that contains all the code that
accesses your database (one for each flavor of database you want to
access). Then I've seen some people have that pass back generic
datasets to another layer or you can have the data access layer
populate an object by itself.
Here is a helpful article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daag.asp
Keanen
J L wrote:
Let me clarify...in VB6 since there was only one flavor of DAO, I
could use a general purpose routine that created the database
connection via Opendatabase() to either Access or SQL based on a user
defined configuration. Now with ADO.Net there are at least two
versions of every thing in the set of Provider Objects (Connection,
Command, DataAdapter and DataReader). How can I create a generic
method to use either the SQLdb. or the OleDb. objects so the rest of
my application can be oblivious to the underlying data source? Or
does
this question even make sense?
TIA
John
I am new to .Net, ADO.Net and OOP programming. Have plenty of
experience with VB6 and DAO but now need to move on. Here is my
simple
question:
I want to create a procedure or class that will handle the creation
of
connections and commands at runtime so that the rest of my code will
not have to know if I am using OleDB, SQLDb or something else.
I hope that is stated clearily. If not, please prod me along the
right
path...I need to be enlightened :>)
John