 |
|
| .NET DotNet Forum Index » ADO .NET Forum » Cannot display ODBC login prompt - want to connect... |
|
Page 1 of 2 Goto page 1, 2 Next |
|
| Author |
Message |
| John Brown... |
Posted: Sun Sep 27, 2009 7:49 am |
|
|
|
Guest
|
Hello All,
In ADO, I can do this
'VBScript
Dim cnn
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = "{SQL Server}"
cnn.Properties("Prompt") = 2 'Prompt if needed, I think
cnn.Open
The SQL Server ODBC login box will appear and the user can then fill in
whatever information is needed: Windows or SQL Server authentication, server
name, etc.
I am trying to write a program that will save a connection string for any
ODBC database.
I cannot find the equivalent of 'cnn.Properties("Prompt") = 2' in ADO.Net. I
am using Visual Basic 2008 Express with the .NET Framework 3.5 SP1.
'Visual Basic .NET
Dim cnn as New OdbcConnection
cnn.ConnectionString = "{SQL Server}"
cnn.Open 'fails because connection string is incomplete
Questions:
1) How can I make the ODBC login box appear in an ADO.Net app, other than
falling back to ADO (or horror of horrors, calling the ODBC API directly)?
2) More generally, is there an equivalent to the
ADODB.Connection::Properties collection in ADO.Net?
Regards,
John Brown. |
|
|
| Back to top |
|
|
|
| Mark Rae [MVP]... |
Posted: Sun Sep 27, 2009 8:11 am |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:5F054111-768C-4FD8-86FF-468FB02F9312 at (no spam) microsoft.com...
Quote: 2) More generally, is there an equivalent to the
ADODB.Connection::Properties collection in ADO.Net?
More pertinently, why on earth are you using ODBC...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net |
|
|
| Back to top |
|
|
|
| John Brown... |
Posted: Sun Sep 27, 2009 8:50 am |
|
|
|
Guest
|
"Mark Rae [MVP]" wrote:
Quote: "John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:5F054111-768C-4FD8-86FF-468FB02F9312 at (no spam) microsoft.com...
2) More generally, is there an equivalent to the
ADODB.Connection::Properties collection in ADO.Net?
More pertinently, why on earth are you using ODBC...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
And what, pray tell, should I be using? |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Sun Sep 27, 2009 11:29 am |
|
|
|
Guest
|
ODBC was effecitvely replaced by OLE DB Providers about 10 years ago and
these providers are available in .NET.
Depending on the database you are using, you'll need a specific provider
with a specific connection string to match it. If you want the user to be
able to supply their user ID and password, that would be a simple matter of
providing a logon form and then take the data from that form and make it
part of the connection string.
For SQL Server, you'd have something similar to this:
Dim con As New System.Data.SqlClient.SqlConnection(connectionStringHere)
Try
con.Open
'use connection here
Catch e As Exception
'handle exceptions here
Finally
con.Close()
con.Dispose()
End Try
Various configurations of connection strings can be found here:
http://ConnectionStrings.com
-Scott
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:E7322825-2163-4B59-9AA4-0085AB397727 at (no spam) microsoft.com...
Quote:
"Mark Rae [MVP]" wrote:
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:5F054111-768C-4FD8-86FF-468FB02F9312 at (no spam) microsoft.com...
2) More generally, is there an equivalent to the
ADODB.Connection::Properties collection in ADO.Net?
More pertinently, why on earth are you using ODBC...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
And what, pray tell, should I be using? |
|
|
| Back to top |
|
|
|
| Mark Rae [MVP]... |
Posted: Sun Sep 27, 2009 1:11 pm |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:197C6525-4154-4C0C-9932-403A0D43CCEE at (no spam) microsoft.com...
Quote: I knew about OleDB. Wasn't ADO built open OleDB as a way of shielding VB
programmers from the complexity of OleDB?
??? Where on earth did you get that from...
As for the "complexity" of OleDb, you're joking, right...?
Quote: The real reason I have been ODBC with ADO is that I am lazy. I cannot
remember
the names of the providers in which I am interested. I have to look them
up each time.
In which case, I don't think I or anyone else can help you...
Quote: In this particular case, my program will conect to an Oracle database, but
I
don't have Oracle here. I'm too lazy to make a trip just so that I can run
my
program (to convert an XML file into records in a table) against an Oracle
database.
As above...
Quote: There does not seem to be a .NET provider for [MS Access] Jet,
Indeed. As mentioned, that's when you use OleDb:
http://www.connectionstrings.com/access
http://www.connectionstrings.com/access-2007
Quote: and even if there were, I would have to write different code depending on
the database
that I was connecting to:
Nope - that's what a DAL based on a factory pattern is for:
http://msdn.microsoft.com/en-us/magazine/cc163766.aspx#S5
http://www.microsoft.com/downloads/details.aspx?familyid=1643758B-2986-47F7-B529-3E41584B6CE5&displaylang=en
Quote: You haven't answered the original question. Can you try this one instead:
If I use the ADO.Net provider for OleDB, and I allow the user to select an
OleDB provider from a list of providers installed on his PC , will I be
able
to display that provider's login box and let the user connect, and then
save
the resulting ConnectionString to be re-used in the future?
Yes.
Quote: Your point is well taken, but as I said earlier, my app needs to work with
2
databases.
See above...
My DAL works with SQL Server, SqlCe, Oracle, MySql and Jet (which some
people incorrectly refer to as Access), and can be dropped *completely*
unmodified into any WinForms or WebForms project. If I ever need to support
another RDBMS, it would be a simple matter of adding it to the factory
pattern.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net |
|
|
| Back to top |
|
|
|
| John Brown... |
Posted: Sun Sep 27, 2009 1:31 pm |
|
|
|
Guest
|
"Scott M." wrote:
Quote:
Depending on the database you are using, you'll need a specific provider
with a specific connection string to match it.
This is what I am trying to avoid. I want to write *one* program that will
work with *two* databases (MS Access and Oracle) with *no* code changes
whatsoever. Even though I know exactly which databases my progam is expected
to work with, so I don't have to support an arbitrary unknown database, I
still want to be able to use the program with a database other than Access or
Oracle. If the OleDB provider has its own login dialog box, I would rather
display that one than make my own form to do the same thing.
With ODBC, this is quite simple. I can present a list of installed ODBC
drivers. When the user selects one, I just need to:
'VBScript
Dim cnn
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = "Driver={" selectedDriver & "}"
cnn.Properties("Prompt") = 2
cnn.Open
If I call OleDBConnection::Open with an incomplete ConnectionString (just
the provider name) can I make the provider display a login dialog box?
Regards,
John Brown. |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Sun Sep 27, 2009 3:44 pm |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:937278FB-2561-43F4-BB09-57D6C3FEF0B2 at (no spam) microsoft.com...
Quote:
"Scott M." wrote:
Depending on the database you are using, you'll need a specific provider
with a specific connection string to match it.
This is what I am trying to avoid. I want to write *one* program that will
work with *two* databases (MS Access and Oracle) with *no* code changes
whatsoever.
Well, think about what you just said. There will objviously have to be code
set up to accomodate the two possible database types, but there's no reason
you can use the DBProvider factory classes to accomodate either database
being used.
http://www.davidhayden.com/blog/dave/archive/2007/10/08/CreatingDataAccessLayerUsingDbProviderFactoriesDbProviderFactory.aspx
Quote: Even though I know exactly which databases my progam is expected
to work with, so I don't have to support an arbitrary unknown database, I
still want to be able to use the program with a database other than Access
or
Oracle. If the OleDB provider has its own login dialog box, I would rather
display that one than make my own form to do the same thing.
There are no "login boxes" for OleDB. As I said, if you want a user to
supply their credentials, you can create your own login form for them to
supply the information to you and you can inject those credentials into the
connection string.
Quote:
With ODBC, this is quite simple. I can present a list of installed ODBC
drivers. When the user selects one, I just need to:
'VBScript
Dim cnn
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = "Driver={" selectedDriver & "}"
cnn.Properties("Prompt") = 2
cnn.Open
If I call OleDBConnection::Open with an incomplete ConnectionString (just
the provider name) can I make the provider display a login dialog box?
Again, no. the login box which you are talking about was provided to ODBC by
the Windows Operating System via the ODBC Managaer. Taking ODBC out of the
picture (which you should) means that the dialogs are gone too.
-Scott |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Sun Sep 27, 2009 4:06 pm |
|
|
|
Guest
|
That should be "no reason you CAN'T use the DBProvider factory classes..."
-Scott
"Scott M." <s-mar at (no spam) nospam.nospam> wrote in message
news:u0I4Ru7PKHA.4428 at (no spam) TK2MSFTNGP02.phx.gbl...
Quote:
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:937278FB-2561-43F4-BB09-57D6C3FEF0B2 at (no spam) microsoft.com...
"Scott M." wrote:
Depending on the database you are using, you'll need a specific provider
with a specific connection string to match it.
This is what I am trying to avoid. I want to write *one* program that
will
work with *two* databases (MS Access and Oracle) with *no* code changes
whatsoever.
Well, think about what you just said. There will objviously have to be
code set up to accomodate the two possible database types, but there's no
reason you can use the DBProvider factory classes to accomodate either
database being used.
http://www.davidhayden.com/blog/dave/archive/2007/10/08/CreatingDataAccessLayerUsingDbProviderFactoriesDbProviderFactory.aspx
Even though I know exactly which databases my progam is expected
to work with, so I don't have to support an arbitrary unknown database, I
still want to be able to use the program with a database other than
Access or
Oracle. If the OleDB provider has its own login dialog box, I would
rather
display that one than make my own form to do the same thing.
There are no "login boxes" for OleDB. As I said, if you want a user to
supply their credentials, you can create your own login form for them to
supply the information to you and you can inject those credentials into
the connection string.
With ODBC, this is quite simple. I can present a list of installed ODBC
drivers. When the user selects one, I just need to:
'VBScript
Dim cnn
Set cnn = CreateObject("ADODB.Connection")
cnn.ConnectionString = "Driver={" selectedDriver & "}"
cnn.Properties("Prompt") = 2
cnn.Open
If I call OleDBConnection::Open with an incomplete ConnectionString (just
the provider name) can I make the provider display a login dialog box?
Again, no. the login box which you are talking about was provided to ODBC
by the Windows Operating System via the ODBC Managaer. Taking ODBC out of
the picture (which you should) means that the dialogs are gone too.
-Scott
|
|
|
| Back to top |
|
|
|
| John Brown... |
Posted: Mon Sep 28, 2009 6:44 am |
|
|
|
Guest
|
"Scott M." wrote:
<snip>
Quote: Forget ODBC, it's archaic and doesn't
perform nearly as well as OleDb.
Good luck!
Why do you think that they have released a new ODBC version (3. for
Windows 7?
Regards,
John Brown. |
|
|
| Back to top |
|
|
|
| Mark Rae [MVP]... |
Posted: Mon Sep 28, 2009 7:33 am |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:D1045989-6EFE-43B0-A0D0-1914205C7960 at (no spam) microsoft.com...
Quote: Forget ODBC, it's archaic and doesn't
perform nearly as well as OleDb.
Why do you think that they have released a new ODBC version (3.  for
Windows 7?
For databases which have neither a native .NET data provider nor an OleDb
provider.
There are still a few, but you aren't using any of them...
I suggest you stick with what you know even though the native .NET data
provider for SQL Server outperforms the ODBC driver by approximately a
factor of 20...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net |
|
|
| Back to top |
|
|
|
| John Brown... |
Posted: Mon Sep 28, 2009 8:18 am |
|
|
|
Guest
|
"Mark Rae [MVP]" wrote:
Quote: "John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:D1045989-6EFE-43B0-A0D0-1914205C7960 at (no spam) microsoft.com...
Forget ODBC, it's archaic and doesn't
perform nearly as well as OleDb.
Why do you think that they have released a new ODBC version (3.  for
Windows 7?
For databases which have neither a native .NET data provider nor an OleDb
provider.
snip
They did not have to add new features, but they did, so as far as they are
concerned ODBC is not dead just yet. |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Mon Sep 28, 2009 2:39 pm |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:D1045989-6EFE-43B0-A0D0-1914205C7960 at (no spam) microsoft.com...
Quote:
"Scott M." wrote:
snip
Forget ODBC, it's archaic and doesn't
perform nearly as well as OleDb.
Good luck!
Why do you think that they have released a new ODBC version (3.  for
Windows 7?
Because they haven't actually dropped the entire technology, but for all
intents and purposes, there is no reason to use ODBC in new application
development unless no OleDbProvider exists but an ODBC driver does. This is
not the case most of the time.
-Scott
Quote:
Regards,
John Brown. |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Mon Sep 28, 2009 2:48 pm |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:843E16CC-2D62-4BF9-939A-4DC806E744F3 at (no spam) microsoft.com...
Quote: After a multitude of posts with much information that is completely
irrelevant to my simple and clearly-stated problem, we're finally getting
somewhere. I have not gone through it yet, but it seems to be a more
complicated and less general technique than the DBProvider class mentioned
by
the other poster.
This is exactly what I've been recommending to you all along. The "factory"
pattern is the same thing as the DBProvider solution I've been suggesting.
Quote:
You haven't answered the original question. Can you try this one
instead:
If I use the ADO.Net provider for OleDB, and I allow the user to select
an
OleDB provider from a list of providers installed on his PC , will I be
able
to display that provider's login box and let the user connect, and then
save
the resulting ConnectionString to be re-used in the future?
Yes.
The other poster who has replied says that you can't. In particular, he
says
that OleDB providers do not have their own login dialog box so I must
supply
my own. Of course, I would rather agree with you.
As I stated, OleDb does not supply ANY form of UI. What I belive Mark was
saying "yes" to was the "could I save the connection string for later use"
part, which you can.
Quote:
Your point is well taken, but as I said earlier, my app needs to work
with
2
databases.
See above...
My DAL works with SQL Server, SqlCe, Oracle, MySql and Jet (which some
people incorrectly refer to as Access), and can be dropped *completely*
unmodified into any WinForms or WebForms project. If I ever need to
support
another RDBMS, it would be a simple matter of adding it to the factory
pattern.
So you support several databases with the same code, but to add another,
you
would have to make a small change. This will work for me, but it is not
the
same as my program being able to connect to an arbitrary database without
my
knowledge or permission.
John, I really am trying to help you out here, but I've got to say that you
seem to be shooting down suggested courses of action, without really having
any knowledge or experience with what's being suggested. To accomplish what
you want is not at all complicated and does not put the burdens on your
end-user that you keep saying it will. Take it from people who have done
exactly what you are saying you want to do.
I wish you good luck with it, but I can't see a continued debate about the
correct course of action with someone who seems to want to shoot down
exactly the solution that they are seeking. If I haven't explained the
solution correctly, my apologies, but you can get just what you want with
the DB Factory paradigm (implemented via the DBProvider classes) and two
basic connection strings that are completed with user imput using the
ConnectionStringBuilder class.
Please take the time to research these items (links previously provided) and
you'll see that it's what you want. It may not have the built in login
boxes that you used to have, but the performance gains as well as the device
indepenence is well worth doing DSN-less connections, which were introduced
13 years ago.
-Scott |
|
|
| Back to top |
|
|
|
| John Brown... |
Posted: Mon Sep 28, 2009 5:16 pm |
|
|
|
Guest
|
"Scott M." wrote:
Quote:
snip
This is exactly what I've been recommending to you all along. The "factory"
pattern is the same thing as the DBProvider solution I've been suggesting.
OK.
Quote:
You haven't answered the original question. Can you try this one
instead:
If I use the ADO.Net provider for OleDB, and I allow the user to select
an
OleDB provider from a list of providers installed on his PC , will I be
able
to display that provider's login box and let the user connect, and then
save
the resulting ConnectionString to be re-used in the future?
Yes.
The other poster who has replied says that you can't. In particular, he
says
that OleDB providers do not have their own login dialog box so I must
supply
my own. Of course, I would rather agree with you.
As I stated, OleDb does not supply ANY form of UI. What I belive Mark was
saying "yes" to was the "could I save the connection string for later use"
part, which you can.
Well, I didn't ask *part* of a question. I asked a whole question, and I am
sure that you cannot deny that I asked it very clearly and concisely, so if
he said "Yes", I can only assume that he must be have been responding to the
whole question.
Quote:
John, I really am trying to help you out here, but I've got to say that you
seem to be shooting down suggested courses of action, without really having
any knowledge or experience with what's being suggested.
I have not shot down anything. I already said that DBProvider looks
promising, but you're right. I won't have anything more to say on this
subject until I try it.
Quote:
... you can get just what you want with
the DB Factory paradigm (implemented via the DBProvider classes) and two
basic connection strings that are completed with user imput using the
ConnectionStringBuilder class.
The very name of this class fills me with ecstasy. This is of course,
exactly what I want to do.
Quote: Please take the time to research these items (links previously provided) and
you'll see that it's what you want.
I will.
Quote: It may not have the built in login
boxes that you used to have, but the performance gains as well as the device
indepenence is well worth doing DSN-less connections, which were introduced
13 years ago.
Not to flog a dead horse, but DSN-less connections existed in ODBC 1.0
(Sep.1992, according to Wikipedia.)
Regards,
John Brown. |
|
|
| Back to top |
|
|
|
| Scott M.... |
Posted: Mon Sep 28, 2009 5:29 pm |
|
|
|
Guest
|
"John Brown" <JohnBrown at (no spam) discussions.microsoft.com> wrote in message
news:2B104035-0ADC-4BBC-8325-C8093F8E4801 at (no spam) microsoft.com...
Quote: Not to flog a dead horse, but DSN-less connections existed in ODBC 1.0
(Sep.1992, according to Wikipedia.)
Well, I wasn't an ODBC expert, but I doubt the accuracy of that statement.
By it's very definition, ODBC required DSN's. The DSN's were the middle-man
created by the ODBC manager. The DSN was the extra layer that is precisely
the thing that causes the performance bottlenecks. It was OleDB that freed
us from ODBC and thus, DSN's. In other words ODBC = DSN.
-Scott |
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Tue Nov 24, 2009 7:04 pm
|
|