I have a VB application that I am trying to upgrade. First I moved it to a new computer. The app worked on a XP, 32bit but when transferred to a Windows 7, 64 bit does not run when it is initially setting up communication to the data base.
I use the sequence of SQLAllocEnv, SQLAllocConnect and then SQLConnect. The first two steps seem to run fine without errors but when running SQLConnect, this error occurs:
[Microsoft][ODBC driver for Oracle][ORACLE]ORA-06413: Connection not open.
What am I missing or didn't I do? Here is the code I used:
Option Explicit
Private Declare Function SQLAllocEnv Lib "odbc32.dll" _
(phenv As Long) As Integer
Private Declare Function SQLAllocConnect Lib "odbc32.dll" _
(ByVal henv As Long, phdbc As Long) As Integer
Private Declare Function SQLConnect Lib "odbc32.dll" ( _
ByVal hdbc As Long, ByVal szDSN As String, _
ByVal cbDSN As Integer, ByVal szUID As String, _
ByVal cbUID As Integer, ByVal szAuthStr As String, _
ByVal cbAuthStr As Integer) As Integer
Private Declare Function SQLFreeEnv Lib "odbc32.dll" _
(ByVal henv As Long) As Integer
Private Declare Function SQLFreeConnect Lib "odbc32.dll" _
(ByVal hdbc As Long) As Integer
Private Declare Function SQLError Lib "odbc32.dll" ( _
ByVal henv As Long, ByVal hdbc As Long, ByVal hstmt As Long, _
ByVal szSqlState As String, pfNativeError As Long, _
ByVal szErrorMsg As String, ByVal cbErrorMsgMax As Integer, _
pcbErrorMsg As Integer) As Integer
Private Declare Function SQLDisconnect Lib "odbc32.dll" _
(ByVal hdbc As Long) As Integer
' ************************************************************************************
' ************************************************************************************
' THE FOLLOWING WAS ADDED TO PROVIDE CONNECTION POOLING. MS CASE# SRZ060810001720
' THIS IS FOUND @ www.support.microsoft.com/kb/237844/en-us
' THIS SHOULD TURN ON CONNECTION POOLING, IT WILL ALLOW THE THE PC TO CONNECT
' FASTER FOR SELL-OUTS BASED ON THE CONNECTION SHOULD ALREADY EXIST.
'
' ************************************************************************************
Const SQL_ATTR_CONNECTION_POOLING = 201
Const SQL_CP_ONE_PER_DRIVER = 1
Const SQL_IS_INTEGER = -6
Const SQL_CP_OFF = 0
Private Declare Function SQLSetEnvAttr Lib "odbc32.dll" ( _
ByVal EnvironmentHandle As Long, _
ByVal EnvAttribute As Long, _
ByVal ValuePtr As Long, _
ByVal StringLength As Long) As Integer
Dim rc As Long
' ****************************************************************
' ORACLE SETUP VARIABLES
' ****************************************************************
Public strOracleLocator$, strOracleProceedure$, strOracleServer$
Public strOracleSubinventory$, strOracleUserID$, strOracleUserPwd$
Public strOracleOrganizationCode As String
Public strOraclePart$, strPrevPartRan$
Public iOracleQty%, iOracleFileCount%
Public bOracleConnected As Boolean
Public bOracleSending As Boolean
Public bOracleEnabled As Boolean
Public bOracleLoggedON As Boolean
Public bOraclePartNumSame As Boolean
Public dOracleLoginQty As Double
Public bOracleConnectionPooling As Boolean
Public bLogONFailed As Boolean
Public bOracleSendManually As Boolean
Public dbOracleSendTime(2, 7) As Date
Public bOracleSendTimeEnable(2, 7) As Boolean
Public dtOracleTempTime(7) As Date
Public bOracleTempTime(7) As Boolean
Public bOracleSendByTime(3) As Boolean
Public bOracleSendByTimeOnce As Boolean
Public strOracleShapeColor As String
Public strOracleLabelText As String
Public bOracle(3) As Boolean
Public bSellAfter(1) As Boolean
Public bCoverONLY(1) As Boolean
Public bStoreOracleData As Boolean
' ************************************************************************************
' ************************************************************************************
Public bOracleSentDuringDownTime As Boolean
Public bOracleManualSend As Boolean
Public bOracleManualDidSend As Boolean
Public bOracleTransaction As Boolean
Private Const SQL_SUCCESS As Long = 0
Private Const SQL_SUCCESS_WITH_INFO As Long = 1
Dim Cn As adodb.Connection
Dim CPw1 As adodb.Command
Dim CPw2 As adodb.Command
Dim Rs As adodb.Recordset
Dim Conn As String
Dim QSQL As String
Dim Oracle_Script As String
Dim p_Organization As String
Dim p_Item As String
Dim p_Trx_Qty As Integer
Dim p_Sub_Inventory As String
Dim p_Locator As String
Dim p_Organization_data As String
Dim p_Item_data As String
Dim p_Trx_Qty_data As Integer
Dim p_Sub_Inventory_data As String
Dim p_Locator_data As String
Public Function IsValidODBCLogin(ByVal sDSN As String, _
ByVal sUID As String, ByVal sPWD As String) As Boolean
Dim henv As Long 'Environment Handle
' ***********************************************************************
' THIS IS A MICROSOFT DOWNLOAD TO VERIFY THE LOGIN ONTO A ODBC DATABASE
' ***********************************************************************
Dim hdbc As Long 'Connection Handle
Dim iResult As Integer
'Obtain Environment Handle
iResult = SQLAllocEnv(henv)
If iResult <> SQL_SUCCESS Then
IsValidODBCLogin = False
Exit Function
End If
'Obtain Connection Handle
iResult = SQLAllocConnect(henv, hdbc)
If iResult <> SQL_SUCCESS Then
IsValidODBCLogin = False
iResult = SQLFreeEnv(henv)
Exit Function
End If
'Test Connect Parameters
iResult = SQLConnect(hdbc, sDSN, Len(sDSN), sUID, Len(sUID), _
sPWD, Len(sPWD))
If iResult <> SQL_SUCCESS Then
If iResult = SQL_SUCCESS_WITH_INFO Then
'The Connection has been successful, but SQLState Information
'has been returned
'Obtain all the SQLState Information
' If frmOracle.Check1.Value Then ShowSQLErrorInfo hdbc, vbInformation
IsValidODBCLogin = True
Else
'Obtain all the Error Information
' If frmOracle.Check1.Value Then ShowSQLErrorInfo hdbc, vbExclamation
' ***********************************************************************
' THE FOLLOWING COMMAND HAS BEEN REM'D OUT TO PREVENT THE ERROR CODE FROM
' POPPING UP ON THE SCREEN AND REQUIRING AN OPERATOR ACKNOWLEDGEMENT
' ***********************************************************************
' ShowSQLErrorInfo hdbc, vbExclamation
IsValidODBCLogin = False
End If
Else
IsValidODBCLogin = True
End If
' ***********************************************************************
' THE FOLLOWING LINE WAS ADDED FROM A RECOMMENDATION FROM MICROSOFT
' CASE # "SRZ060711002202" E-MAIL SUPPORT Ying Liu
' FROM THE ORIGINAL DOWNLOAD FROM MICROSOFT'S KB, DID NOT HAVE THIS LINE
' IN IT. THIS ITEM IS DELCARED AT THE TOP OF THIS MODULE
' ***********************************************************************
iResult = SQLDisconnect(hdbc)
'Free Connection Handle and Environment Handle
iResult = SQLFreeConnect(hdbc)
iResult = SQLFreeEnv(henv)
End Function
Public Sub ShowSQLErrorInfo(hdbc As Long, iMSGIcon As Integer)
' ***********************************************************************
' THIS IS A MICROSOFT DOWNLOAD TO VERIFY THE LOGIN ONTO A ODBC DATABASE
' ***********************************************************************
Dim iResult As Integer
Dim hstmt As Long
Dim sBuffer1 As String * 16, sBuffer2 As String * 255
Dim lNative As Long, iOutlen As Integer
sBuffer1 = String$(16, 0)
sBuffer2 = String$(256, 0)
Do 'Cycle though all the Errors
iResult = SQLError(0, hdbc, hstmt, sBuffer1, lNative, sBuffer2, _
256, iOutlen)
If iResult = SQL_SUCCESS Then
If iOutlen = 0 Then
MsgBox "Error -- No error information available", _
iMSGIcon, "ODBC Logon"
Else
MsgBox Left$(sBuffer2, iOutlen), iMSGIcon, "ODBC Logon"
End If
End If
Loop Until iResult <> SQL_SUCCESS
End Sub