Home:ALL Converter>VB6 program using ODBC will not run in Win7 64

VB6 program using ODBC will not run in Win7 64

Ask Time:2012-09-22T00:15:26         Author:Bob T

Json Formatter

I have an old VB6 program that uses a MySQL 4.07 database. It was developed on my Win XP 64 bit machine. It works fine on my Win XP 64 machine and it works fine on my Win7 64 bit machine. But when one of our users tries to run it on their Win7 64 machine, it fails with

    "Run-time error '-2147467259 (80004005)': [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".  

What is odd is that they have installed the ODBC drivers and have them in SysWOW64 and system32.

The following code is executed in Form_Load and is more than likely where the error occurs (note that the 32 bit driver is for NT Server 2.5 and the 64 bit one is a newer version.):

    If IsHost64Bit() = True Then
        mstrConnString = "driver=MySQL ODBC 3.51 Driver;server=mysqleng;database=engprogs;port=3306;UID=user;PWD=########"
        mstrConnString = "driver=MySQL;server=mysqleng;database=engprogs;port=3306;UID=user;PWD=########"
    End If

    Set ADOCn = New ADODB.Connection
    ADOCn.ConnectionString = mstrConnString
    ADOCn.Open mstrConnString

I've checked the properties of odbcad32.exe inside SysWOW64 and the driver tab shows MySQL ODBC 3.51 on the users machines!

Any ideas would be greatly appreciated.

Thanks, Bob

Author:Bob T,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12534237/vb6-program-using-odbc-will-not-run-in-win7-64
Bob T :

The discussion with Mark Kram led me to try and install VB6 on the Win7 64 bit computer. During the install I ignored the compatibility warnings. It installed and works fine as far as I can tell. Because of that I was able to single step thru the code and discovered that \"IsHost64Bit()\" was not working properly in Win7 64! The \"IsHost64Bit()\" routine was indicating that the 64 bit computer was 32 bit! It was therefore loading the \"mstrConnString\" from the 32 bit. That is why it was failing when the program starts. \n\n\"IsHost64Bit()\" requires:\n\nPrivate Declare Function GetProcAddress Lib \"kernel32\" _\n(ByVal hModule As Long, ByVal lpProcName As String) As Long\n\nPrivate Declare Function GetModuleHandle Lib \"kernel32\" _\nAlias \"GetModuleHandleA\" (ByVal lpModuleName As String) As Long\n\nPrivate Declare Function GetCurrentProcess Lib \"kernel32\" () As Long\n\nPrivate Declare Function IsWow64Process Lib \"kernel32\" _\n(ByVal hProc As Long, ByRef bWow64Process As Boolean) As Long\n\n\nThe \"IsHost64Bit()\" routine:\n\nPublic Function IsHost64Bit() As Boolean\nDim handle As Long\nDim is64Bit As Boolean\n\n' Assume initially that this is not a WOW64 process\nis64Bit = False\n\n' Then try to prove that wrong by attempting to load the\n' IsWow64Process function dynamically\nhandle = GetProcAddress(GetModuleHandle(\"kernel32\"), \"IsWow64Process\")\n\n' The function exists, so call it\nIf handle <> 0 Then\n IsWow64Process GetCurrentProcess(), is64Bit\nEnd If\n\n' Return the value\nIsHost64Bit = is64Bit\nEnd Function\n\n\nI replaced \"IsHost64Bit()\" with:\n\nDim wmi, prc\nDim prcOS As String\n\nSet wmi = GetObject(\"winmgmts:\\\\\")\nFor Each prc In wmi.execQuery(\"SELECT * FROM Win32_Processor\")\n Debug.Print prc.Name, \"Bit Sizes - ADDR:\"; prc.AddressWidth, \"DATA:\"; prc.DataWidth\n prcOS = Str(prc.DataWidth)\nNext\n\n\nAnd the Form_Load routine now correctly checks for 64 bit as follows:\n\nIf prcOS = \" 64\" Then\n mstrConnString = \"driver=MySQL ODBC 3.51 Driver;server=mysqleng;database=engprogs;port=3306;UID=user;PWD=########\"\nElse\n mstrConnString = \"driver=MySQL;server=mysqleng;database=engprogs;port=3306;UID=user;PWD=########\"\nEnd If\n\nSet ADOCn = New ADODB.Connection\nADOCn.ConnectionString = mstrConnString\nADOCn.Open mstrConnString\n",