First, for the benefit of others who may find this thread, let me state a
method of displaying a dialog box prompt that will let a user connect to any
data source that has an ADO.NET provider. This program will work unmodified
with SuperDB 2012, even though their website is not up yet, and I have no
information about the connection string that I will need.
' sProviderName can be selected from a list box. Of course, we would
' display the friendly names, but use the object names internally
Dim dbpf as DBProviderFactory = GetFactory(sProviderName)
'Get a ConectionStringBuilder that will build a connection string for
sProviderName
Dim csb as DbConnectionStringBuilder = dbpf.ConnectionStringBuilder()
' Use a PropertyGrid contol on your form to display the properties
' of the connection string, which will correspond to the keywords in
' the connection string; user id, password, etc.
PropertyGrid1.SelectedObject = csb
' When you run your form, it will show a property grid that
' corresponds to the conection string for your database.
' After you show the form, you can create a generic connection object
Dim cnn as DbConnection = dbpf.CreateDbConnection()
cnn.ConnectionString = csb.ConnectionString
cnn.Open
' At this point, you will be connected to a database about which you knew
' nothing beforehand. You could have started with an empty
' config file, but you can save the whole string or any part of it in the
'config file.
Now, I will address the points that you raised.
:
You are telling me that you'll need to connect to Access and
Oracle, so that means you need to have two different connection strings.
This is the sequence of events, which I evidently did not make clear.
- I needed to connect to Access and Oracle with one program.
- The initial suggestion was that I should write:
If Access
DoThis
Else
DoThat
End If
- I was not interested, because I never had to do that before.
- So I asked myself "Does this mean that I cannot write what the ODBC
documentation calls a Generic application, i.e., one that 'must work with a
variety of different DBMSs and that the developer does not know beforehand
what these DBMSs will be.'"?
- The DbProviderFactory methods and generic Dbxxx classes were suggested,
but there was still a gap. In my opinion, such an application needs a way to
present a login box that is appropriate for the database. Yes, the user can
edit my config file, but if they wanted to edit config files, they would use
Linux.
- The PropertyGrid control was the final piece of the puzzle. It allows me
to present a GUI that will help the user to build a connection string.
First, I reject the scenario you have started out with. All you need from
the end user is their id, password, and database.
What you need depends entirely on what the developers of the database say
you need. You sent me to ConnectionStrings.com, so you know this. SuperDB's
connection string is not there, by the way.
You would not present
them with a list of OleDb Providers because they wouldn't understand what
that list represents.
I am assuming that ADO.NET providers have friendly names like "Data Provider
for SuperDB" for display purposes, and a name like Data.SuperDB.Client for
use in programs. Also, we never defined "user". If you use my program, then
you are a user, even if you are an MVP. I also don't care who is using the
program.
This is less a programming issue and more of a configuration issue. But, if
you need windows authentication, you can certainly set up the connection
string to use it.
At this point, I don't know which authentication methods are supported by
SuperDB, and I no longer care, because I now have a way to present the
options to them. They can set up their environment however they like. I don't
need to know. Don't ask, don't tell.
This is where I am bit confused. Are you saying that the user gets to tell
your program if Windows Authentication is being used? This is not something
that end users know and understand and hardly something that you'd ask them
to tell you. You should know how your users need to connect and code for
that.
Excel allows you to populate a spreadsheet with data from a database. You
can select a DSN, or you can create one on the fly. If you select the SQL
Server driver, it will present you with a login box with user name, password,
etc., as well as a "Use trusted connection" checkbox, which you can tick or
not. The Excel developers don't know whether your data is in SQL Server or
text files. They don't care whether you use WIndows or SQL Server
authentication. They also expect that Excel will be able to import data from
SuperDB when it is released, and they don't tell anybody that they need to
edit a file to connect to MS Access, SQL Server, or SuperDB.
Solution, the SqlConnectionStringBuilder class. This is not the problem you
think it is.
The solution is the generic ConnectionStringBuilder, along with a
PropertyGrid to allow the user to set the properties. It's useless without
the PropertyGrid. Or more accurately, I woud have to find out how the
PropertyGrid does what it does, but I have no reason to do that unless I was
trying to display a really elegant login box with tabs and what not.
Your OP was that you need to code against Access or Oracle, now you are
saying it could be anything?
Explained above. I *need* to support Access and Oracle, but I *want* to
support anything.
With the help of the PropertyGrid control, DbProviderFactory can certainly
help me figure out my connection string.
Since SuperDB has not been released yet, I cannot possibly create my own
dialog. I don't know what will be required. You keep insisting that all you
need is a user id, password and database, but it simply is not true. I am
going ask SuperSoft to add a surprise required parameter for connection.
We'll see how far you get with a dialog box with fields just for user name,
password and database.
What I am having trouble understanding is that it seems that you want the
user to tell the program (or you think that I'm saying that a user should
tell the program) explicit details about how to connect to the desired data
source.
This is exactly what I want. Users of Excel, Access, Crystal Reports and a
host of other applications do this every day. The real mystery is why you
think that it is so strange.
But none of this matters anymore. The problem has been solved. I can do
using ADO.NET what I used to do using ODBC.
Regards,
John Brown.