[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Detect if ODBC is installed?

Tim

9/4/2002 1:47:00 AM

I'd like to do this:

Dim Conn as IDBConnection
If usermachine has ODBC installed then
Conn = New Microsoft.Data.Odbc.OdbcConnection()
else
Conn = New OleDb.OleDbConnection()

However, references to ODBC generate compiler errors if the user's machine
does not have the classes in the ODBC namespace installed. Is there a way
to include/exclude source lines conditionally in order to prevent such
errors?

Thanks
Tim Romano





3 Answers

(Hussein Abuthuraya(MSFT))

9/4/2002 9:06:00 PM

0

Tim,

You may be able to try and locate the ODBC dll in the installation folder or check the registry for specific entry but all this doesn't mean that the ODBC . NET Data Provider
should be functional or installaed correctly.

I think, the best approach is to wrap the expected line that may generate an error in a try... catch.. block and in the catch block decide what to do with that exception.


Thanks,
Hussein Abuthuraya
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....


Tim

9/5/2002 12:13:00 AM

0

Hi Hussein,
Thanks for the reply.

It is the JIT compiler that generates an error when it cannot find the odbc
provider classes. It's not a runtime error so I cannot trap the error using
Try/Catch.

Is there any way to instruct the JIT compiler to do conditional compilation,
something like this:

##IF {odbc classes are present}
conn = new odbc connection
##ELSE
conn = new oledb connection
##END IF

Of course, I won't know the state of a deployment PC at development time, so
standard conditional compilation won't suffice. This would be a very nice
feature to have for the future:

If {some special class is installed. e.g. a native provider}
do something special
else
do something generic


Tim Romano


"Hussein Abuthuraya(MSFT)" <HussAbOnline@microsoft.com> wrote in message
news:35Bqp5EVCHA.2244@cpmsftngxa10...
> Tim,
>
> You may be able to try and locate the ODBC dll in the installation folder
or check the registry for specific entry but all this doesn't mean that the
ODBC . NET Data Provider
> should be functional or installaed correctly.
>
> I think, the best approach is to wrap the expected line that may generate
an error in a try... catch.. block and in the catch block decide what to do
with that exception.
>
>
> Thanks,
> Hussein Abuthuraya
> Microsoft Developer Support
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.co....
>
>


Fernando Salas

9/9/2002 3:30:00 AM

0

Hi

Did u try to load the Assembly dynamically, then u use the classes
through the interfaces, which are defined in System.Data, I used that to
provide a Wrapper that can be use to use direct, OLE or ODBC drivers without
changing a line of code, and as far as I tested it worked, if u are
interested and have doubts mail me

Hope this helps;

Fer

"somebody" <somebody@yahoo.com> wrote in message
news:O94frgGVCHA.2136@tkmsftngp08...
> Hi Hussein,
> Thanks for the reply.
>
> It is the JIT compiler that generates an error when it cannot find the
odbc
> provider classes. It's not a runtime error so I cannot trap the error
using
> Try/Catch.
>
> Is there any way to instruct the JIT compiler to do conditional
compilation,
> something like this:
>
> ##IF {odbc classes are present}
> conn = new odbc connection
> ##ELSE
> conn = new oledb connection
> ##END IF
>
> Of course, I won't know the state of a deployment PC at development time,
so
> standard conditional compilation won't suffice. This would be a very nice
> feature to have for the future:
>
> If {some special class is installed. e.g. a native provider}
> do something special
> else
> do something generic
>
>
> Tim Romano
>
>
> "Hussein Abuthuraya(MSFT)" <HussAbOnline@microsoft.com> wrote in message
> news:35Bqp5EVCHA.2244@cpmsftngxa10...
> > Tim,
> >
> > You may be able to try and locate the ODBC dll in the installation
folder
> or check the registry for specific entry but all this doesn't mean that
the
> ODBC . NET Data Provider
> > should be functional or installaed correctly.
> >
> > I think, the best approach is to wrap the expected line that may
generate
> an error in a try... catch.. block and in the catch block decide what to
do
> with that exception.
> >
> >
> > Thanks,
> > Hussein Abuthuraya
> > Microsoft Developer Support
> >
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> >
> > Are you secure? For information about the Microsoft Strategic Technology
> Protection Program and to order your FREE Security Tool Kit, please visit
> > http://www.microsoft.co....
> >
> >
>
>