Generic OLEDBConnection

N

Nicolas Hilaire

Hi all,

i need to make a connection to a database, but i can't know in advance
what kind of database it will be. That can be an oracle database,
access database, sql server database, and so on ...

My user will create an ODBC DSN and will set it's name in my
application.

Then i will have only this information : the DSN NAME

i thought that odbc can implement a generic way of connection. So i've
create an OleDbConnection object :

Private theOleDbConnection As OleDbConnection
....
theOleDbConnection = New OleDbConnection
theOleDbConnection.ConnectionString = ??

what kind of connection string should i use (i've tried some without
any result) ? is there's an other way to have a generic connection ??

thanks a lot in advance for your help.

Nicolas H.
 
G

Grzegorz Danowski

Uzytkownik "Nicolas Hilaire said:
Hi all,

i need to make a connection to a database, but i can't know in advance
what kind of database it will be. That can be an oracle database,
access database, sql server database, and so on ...

My user will create an ODBC DSN and will set it's name in my
application.

Then i will have only this information : the DSN NAME

Why not Odbc provider and OdbcConnection, for example:
OdbcConnection con = new OdbcConnection("dsn=MyDsn;")

Regards,
Grzegorz
 
N

Nicolas Hilaire

Grzegorz Danowski said:
Why not Odbc provider and OdbcConnection, for example:
OdbcConnection con = new OdbcConnection("dsn=MyDsn;")

Regards,
Grzegorz

yes, why not ? but i have this exception :

ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's
SQLSetConnectAttr failed ERROR [01000] [Microsoft][ODBC Driver
Manager] The driver doesn't support the version of ODBC behavior that
the application requested (see SQLSetEnvAttr). ERROR [01S00]
[Microsoft][ODBC driver for Oracle]Invalid connection string attribute

with this code :

Dim con As New Odbc.OdbcConnection("dsn=myDsn;User
Id=myUser;Password=myPwd;"
con.Open() 'exception comes on this line

but i can connect to my database by this way, but you've understood
that it's not the way i want :

dim theOleDbConnection as New
OleDbConnection("Provider=oraOLEDB.Oracle;SERVER=myServer;Data Source
=myDsn;User Id=myUser;Password=myPwd;")
theOleDbConnection.Open() ' Working


Thanks to help me to have a generic connection independtly to the
database

Regards

Nicolas H.
 
N

Nicolas H.

Maybe it's not possible ???

No one have an idea ?

thanks

Nicolas H.



Grzegorz Danowski said:
Why not Odbc provider and OdbcConnection, for example:
OdbcConnection con = new OdbcConnection("dsn=MyDsn;")

Regards,
Grzegorz

yes, why not ? but i have this exception :

ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's
SQLSetConnectAttr failed ERROR [01000] [Microsoft][ODBC Driver
Manager] The driver doesn't support the version of ODBC behavior that
the application requested (see SQLSetEnvAttr). ERROR [01S00]
[Microsoft][ODBC driver for Oracle]Invalid connection string attribute

with this code :

Dim con As New Odbc.OdbcConnection("dsn=myDsn;User
Id=myUser;Password=myPwd;"
con.Open() 'exception comes on this line

but i can connect to my database by this way, but you've understood
that it's not the way i want :

dim theOleDbConnection as New
OleDbConnection("Provider=oraOLEDB.Oracle;SERVER=myServer;Data Source
=myDsn;User Id=myUser;Password=myPwd;")
theOleDbConnection.Open() ' Working


Thanks to help me to have a generic connection independtly to the
database

Regards

Nicolas H.
 
N

Nicolas Hilaire

no one have a solution for this problem ??


Grzegorz Danowski said:
Why not Odbc provider and OdbcConnection, for example:
OdbcConnection con = new OdbcConnection("dsn=MyDsn;")

Regards,
Grzegorz

yes, why not ? but i have this exception :

ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's
SQLSetConnectAttr failed ERROR [01000] [Microsoft][ODBC Driver
Manager] The driver doesn't support the version of ODBC behavior that
the application requested (see SQLSetEnvAttr). ERROR [01S00]
[Microsoft][ODBC driver for Oracle]Invalid connection string attribute

with this code :

Dim con As New Odbc.OdbcConnection("dsn=myDsn;User
Id=myUser;Password=myPwd;"
con.Open() 'exception comes on this line

but i can connect to my database by this way, but you've understood
that it's not the way i want :

dim theOleDbConnection as New
OleDbConnection("Provider=oraOLEDB.Oracle;SERVER=myServer;Data Source
=myDsn;User Id=myUser;Password=myPwd;")
theOleDbConnection.Open() ' Working


Thanks to help me to have a generic connection independtly to the
database

Regards

Nicolas H.
 

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