问题
I am working on one .vbs file in which I am connecting to DB using below lines of code and than running some queries.
Set cm = CreateObject("ADODB.Command")
cm.ActiveConnection = "Driver={Microsoft ODBC for Oracle};Server ="+sInst+"; UID="+sUID+";PWD="+sPWD
cm.CommandType = 1
cm.CommandText = sSQL
cm.Execute()
Set cm = Nothing
Strange thing for me is when I am copying these lines to QTP and run it from QTP, it's working fine. But when running .vbs file (by double clicking and from cmd), it is giving me below error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I've other machine on which it's working fine both the way. I tried my best to verify all the things in both the machine, but I am not getting it.
I appreciate any thought / help / suggestion.
Thanks.
Quick update:
As vbs is not working I tried googled and create batch file with below line:
C:\Windows\SysWoW64\cscript.exe //NoLogo filepath\xyz.vbs
And its working now.
So question is how run vbs using ODBC from SysWoW64 and not from system32...?
回答1:
Processes on 64-bit Windows are either pure 32-bit or pure 64-bit.
By default 64-bit Windows is executing your vbscript in a 64-bit engine which cannot call any 32-bit DLLs.
64-bit VBScript will use 64-bit ODBC which will only be able to call 64-bit Oracle software (if installed).
32-bit VBScript will use 32-bit ODBC which will only be able to call 32-bit Oracle software (if installed).
As you have discovered the 32-bit versions of most built-in Windows programs are hidden away from view on 64-bit Windows. You have to explicitly run the 32-bit version of ODBC administrator or CSCRIPT yourself.
From what you describe, you seem to have 32-bit Oracle software installed and configured on your machine. 64-bit Oracle software usually needs to be installed and configured separately.
回答2:
Try following:
Go to the following path:
C:\Windows\SysWOW64\odbcad.exe
Double click and pop-up will be opened:
Go to System DSN
Add
Now Choose
Oracle
inOraclient11g_home 1
Now one pop up again open with the following fields:
Data Source Name:PQALN07 (DB NAME)
Description: PQALN07
TNS Service Name: PQALN07 (DB NAME)
User Id : RISK (Schema Name)
By adding above DSN your problem will got resolved.
Now run your VB code using macro and you'll get no error this time.
来源:https://stackoverflow.com/questions/20227569/microsoftodbc-driver-manager-data-source-name-not-found-and-no-default-drive