Blog Archives
List OLE/ODBC Providers with .NET
Recently I wanted to be able to list the OLE/ODBC Providers installed on a system. Not horribly hard, but also didnt have a ton of luck finding info on how to do this.
OLE
For OLE there is a .NET library that allows you to do this fairly easily. I focused in on the wrong method at first but thanks to help from BigTeddy over at the Technet Powershell forums the problem was resolved.
System.Data.OleDBEnumerator class has a GetElements method that will return a list of available providers.
(New-Object system.data.oledb.oledbenumerator).GetElements()
ODBC
Oddly enough, you would think that the System.Data.ODBC namespace would have something along those lines, but no. If it does, I cant find it. However, you can pull it from the registry fairly easily from the following location.
HKLM:\Software\ODBC\ODBCINST.INI\ODBC Drivers
Get-ItemProperty 'HKLM:\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers' #32 bit drivers on a 64 bit system here Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers'
DB2 ODBC connection crashes with an Access Violation in DB2APP64.DLL
Im trying to work with DB2 (you’ll see a few more posts in regards to this) and I installed the ODBC driver on to my Win7 box and tried a simple connection/query with powershell, something like this.
$connstr = "DRIVER={IBM DB2 DRIVER for ODBC - C:/DB2ODBC};Database=myDB;Hostname=myServer;Port=1234;Protocol=TCPIP;Uid=user;Pwd=password;"
$conn = New-Object data.odbc.odbcconnection $connstr
$conn.open()
$cmd = new-object data.odbc.odbccommand
$cmd.connection = $conn
$cmd.commandtext = "select * from myTable"
$cmd.executereader()
Normally this would be fine, but in the case of DB2, it crashes powershell stating there was an Access Violation with DB2APP64.DLL.
After a bit of screwing around, what I found was that this happens when you try to access a 32bit database (yeah, I have a 32bit DB2 system) from a 64 bit system.
Installing the 32 bit odbc driver and using 32bit powershell resolves this. Not how i’d like it to go, but, its all I could come up with.
