Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Invalid procedure call or argument" error on "New ADODB.Connection" only if compiled on Windows 7

Tags:

vb6

adodb

I'm experiencing some problem when I compile some legacy apps on VB6 since I got a new development machine in windows 7. (my old one was on Windows XP.)

If I compile the project on my XP machine, everything is fine. If I compile the same project on my Windows 7 machine, it still run fine one it, but if I try to run it on a XP machine, I got this error.

Error Number : 5
Description : Invalid procedure call or argument

Thanks to my error handler, I know that the line that throw this error is :

    Dim objConn As ADODB.Connection
--> Set objConn = New ADODB.Connection

I compared the references on both machines and the Project - References are the same : (Microsoft ActiveX Data Objects 2.7 Library)

What could cause this error?

like image 550
DavRob60 Avatar asked Jan 20 '12 19:01

DavRob60


2 Answers

This is a known problem in SP1 for Win7 which will be fixed in SP2.

The way to handle the issue in SP1 is to copy the old ADO typelib file from Win7 RTM in C:\Program Files (x86)\Common Files\System\ado and register it there.

Registering this old ADO typelib is not a trivial task as numerous forum threads have shown. Here is a batch file we use in our shop to fix ADO typelib issue:

@echo off
set regtlib="%windir%\Microsoft.NET\Framework\v4.0.30319\regtlibv12.exe"
set subinacl="%~dp0subinacl.exe"
set target_dir=%CommonProgramFiles%\System\ado
if not "%CommonProgramFiles(x86)%"=="" set target_dir=%CommonProgramFiles(x86)%\System\ado

copy "%~dp0msado28_old.tlb" "%target_dir%\msado28_old.tlb" > nul
%subinacl% /subkeyreg HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib\{2A75196C-D9EB-4129-B803-931327F72D5C} /setowner=Administrators > nul
%subinacl% /subkeyreg HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib\{2A75196C-D9EB-4129-B803-931327F72D5C} /grant=Administrators=F > nul
%subinacl% /subkeyreg HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\TypeLib\{2A75196C-D9EB-4129-B803-931327F72D5C} /setowner=Administrators > nul
%subinacl% /subkeyreg HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\TypeLib\{2A75196C-D9EB-4129-B803-931327F72D5C} /grant=Administrators=F > nul
%regtlib% -u "%target_dir%\msado28.tlb"
%regtlib% "%target_dir%\msado28_old.tlb"

You need both msado28_old.tlb and subinacl.exe placed in the same folder as the install.bat file and .NET Framework 4.0 setup for the regtlibv12.exe utility.

Now you can recompile your projects referencing ADO on the Win7 box with no compatibility issues on previous versions of Windows.

like image 132
wqw Avatar answered Nov 20 '22 08:11

wqw


This is a known Microsoft issue, but I don't think it was a bug; I believe compatibility was broken for security reasons. The problem could have existed on a non-SP1 builds if you had a certain hotfix installed. There are a couple of options referenced in the Microsoft KB. Here is another article providing an update.

We ran into this problem and we decided to deploy the Backwards Compatibility patch on all developer machines and replace all legacy ADO references with the Backwards Compatibility reference. This has worked well for us.

like image 2
UnhandledExcepSean Avatar answered Nov 20 '22 08:11

UnhandledExcepSean