Scott M. said:
No, not necessarily.
If you are going to possibly deal with two different
databases (regardless of what you intend to do with those databases), your
application must be prepared to connect to the two different databases.
There's no getting around that.
Please forget the .NET evangelism for a minute and concentrate on what I am
saying. Very early in the piece, I posted ADO code that could connect to any
database without knowing anything beforehand except the driver name. If you
have a generic API that will handle specific objects of different types, it
is wise to have ways of querying the objects to find out their capabilities,
ways to tell them to configure themselves, etc.
What you are telling me is that if I am writing a word processor and my app
wants to print, it should display a standard print dialog box, and if my
users want to use some printer-specific feature that I didn't think of, then
too bad. Fortunately it doesn't worklike that. The printer driver knows how
to configure the printer, so neither my app nor GDI needs to know what the
printer is capable of. However, ny GDI code to print would be exactly the
same, regardless of the printer. I do not consider this to be a bogus concept.
Well, you need to know the basics of the connection string and can populate
the unknowns at runtime with data from the client. If you want to connect
to Access, you must know how to do that. If you want to connect to Oracle,
you must know how to do that as well. But, we're just talking about the
connection string here. The beauty of the ADO .NET objects is that once
you've made your connection, you use the objects the same way.
I may be wrong, but I'm getting the impression that you belive you can (or
should be able to) code a database application that *may* need to connect to
one of two database types without knowing how to code or having to code that
functionality.
Well, if you don't know the details of the connections you need to make at
design-time, then when else would you get them but run-time? And if you
don't have the information and only the end user does, then who else can you
ask to supply the detials? You should only need to ask them for their user
name, password, and database.
Now I understand. You are assuming that connecting to a database is just a
matter of supplying credentials. (By the way, you left out server). Even
supplying credentials can be tricky. Consider SQL Server, but remember that
my app has no built-in knowledge of SQL Server. I present a list box with the
names of all OleDB providers on your computer. You select the one for SQL
Server. I display my generic box to get your user name, password, database
and server. I Build my ConnectionString: Provider=whatever;Data Source=User
Id=johnbrown;Password=password;I
Problem: Your environment uses Windows Authentication.
Problem: Even if you leave the fields blank, you still cannot connect,
because I need to specify the keyword to turn on Windows authentication.
Problem: the program doesn't know that.
There are more problems, such as:
Problem: How do I specify the database? Sometimes, the keyword is "Initial
Catalog", sometimes it is "Database"; there may be others. There are endless
keywords. Some are necessary, some are optional. For example, maybe system
tables are hidden by default (SQL Anywhere), but now I need to see them. How
would I know how to make system tables visible?
You can connect to all sorts of databases, and things that are not really
databases, such as a SharePoint site, an MS Exchange Server, etc. A generic
dialog box will not work for all data sources.
Your users don't need to even hear the words "connection string" or "OleDb",
but yes, shouldn't they know where their own data is and their own
credentials to access it?
It's not all about credentials. See above.
The DBProvider Factory will only help you code one pattern that can work for
the two different databases, it's not going to help you figure out your
connection strings. Honestly, (and I may be missing something here),
Yes, you certainly are, but I hope that my latest explanation clears things
up.
but I
am a bit dumbfounded that you have resistence to the idea that a user would
need to supply credentials to access a secured resource.
I have not the slightest idea what you are talking about. I am resisting the
idea that with backward, "dead" technology, I could write a program to
connect to a database and execute a few inserts and selects without knowing
or caring (much) about the database,in the same way that a program can print
regardless of the printer, or send emails without knowing which email program
is installed. Now I have to care, because I can't connect unless I specify a
correct connection string.
You seemed to be
ok with the ODBC login dialog popping up to promt the user to fill in the
details, why are you having trouble with having them do the exact same
thing, but with a dialog that you create?
It's not all about credentials. You are telling me that if I want to write
an app that will work with any database (let's say any database that has a
certain minimum capability), then I would have to write a login dialog box
for each one. This is not practical. Anyway, I have not investigated
DBProvider yet.
I'm not sure what your point is here. OleDb is NOT ODBC. Comparing the two
architectures for similarities is futile.
I am saying that the ability to connect to a database without knowing the
details is not magic; it was provided by each ODBC driver. If OleDB providers
do not have this capability, then it is a backward step.
Regards,
John Brown.