Jump to content

[RESOLVED] Detect ADODB.Connection*


Recommended Posts

Hi,

One of the issues i noted yesterday while using the MySQL.au3 UDF is that, of course, if the user doesn't have the MySQL Connector Installed, the wouldn't be able to use the program. What I'd like to know is, while I know how to detect if they have the driver installed, is it possible to detect of they have access to the COM OBJECT: ADODB.Connection*. One of my clients used to have access, and then they kept reinstalling the mysql connector, which broke their ADODB.Connection classes, so they kept getting the Object.Conn error.

Is there a way to actually detect to ensure, or test to ensure, that the connection WILL work?

Thanks!

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Well you could check for errors after _MySQLConnect(). Or you can check this registry key to see if MySQL is present:

"HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"

Link to comment
Share on other sites

Well you could check for errors after _MySQLConnect(). Or you can check this registry key to see if MySQL is present:

"HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"

Unfortunately, the way the UDF is setup; if $ObjConn.open fails it kills the entire program with a fatal error. Checking to see if MySQL is present is ok; however some times, like the case of my client, while the mysql driver was present the COM Object (ADODB.Connection) was not, which caused the offending fatal error.

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Unfortunately, the way the UDF is setup; if $ObjConn.open fails it kills the entire program with a fatal error. Checking to see if MySQL is present is ok; however some times, like the case of my client, while the mysql driver was present the COM Object (ADODB.Connection) was not, which caused the offending fatal error.

Do you think simply search for the object within the Classes node in the registry would be enough:

HKLM\Software\Classes\ADODB.Connection or AdoDB.Connection.2.8 ??

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Well the mysql udf isn't checking for errors after ObjCreate():

$ObjConn = ObjCreate("ADODB.Connection")
      $ObjConn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT=" & $iPort & ";CHARSET=UTF8;")
      If @error Then

You can check for @ERROR right after ObjCreate(). This should avoid script failure.

Or if you don't want to modify the UDF:

If IsObj(ObjCreate("ADODB.Connection")) Then
 _MySQLConnect()
 EndIf
Edited by weaponx
Link to comment
Share on other sites

Well the mysql udf isn't checking for errors after ObjCreate():

$ObjConn = ObjCreate("ADODB.Connection")
    $ObjConn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT=" & $iPort & ";CHARSET=UTF8;")
    If @error Then

You can check for @ERROR right after ObjCreate(). This should avoid script failure.

I'll change it to the following:

Func _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{MySQL ODBC 3.51 Driver}", $iPort=3306)
    Local $v = StringMid($sDriver, 2, StringLen($sDriver) - 2)
    Local $key = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", $val = RegRead($key, $v)
    If @error or $val = "" Then
        SetError(2)
        Return 0
    EndIf
    $initConn2 = GUICtrlCreateLabel("MySQL Ticket Server, Please Wait....", 190, 310, 300, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, 12, 20, 0, "Comic Sans MS")
    $ObjConn = ObjCreate("ADODB.Connection")
    If @error Then
        $objConn = ObjCreate("ADODB.Connection.2.8")
        If @error Then
            Msgbox(0,"Remote ObjCreate Test","Failed to open remote Object. Error code: " & hex(@error,8))
            Exit
        EndIf
    EndIf
    $ObjConn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)
    If @error Then
        tooltip("")
        SetError(1)
        Return 0
    Else
        Return $ObjConn
    EndIf
EndFunc ;==>_MySQLConnect

At least this way it tries both ADODB.Connection strings that SHOULD exist. And if not, give me an error and quit. Not sure what else I can do.

I have been reading up on the issue w/ Microsoft, and while you CAN reinstall the MDAC components on Windows XP SP2, it can be quite tedious. I do note also that MDC_TYP.exe is a good program to run as well which reinstalls MDAC, but must be ran in Windows 2000 mode to work lol. This is turning into quite a headache.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

See my edit above.

Added your IsObj() command to the UDF on my end to always test for it. But added 2 checks at the start; checks if MySQL connector is installed, and checks if the ADODB.Connection* COM Object even exists in Classes, and if it does to ensure that it has a CLSID (app name associated with it). Thus, if it is borked for whatever reason, i should know about it before even starting the main part of the program.

Note, i do all of these checks inside of the splash screen, so some of this is just fluff code, and it's here just for reference on my end :) Thanks for the help weapon :(

;-///////////////////// Version information ////////////////////////
$AppVersion = "0.9.7.3.2"
$img = @ScriptDir & "\background.jpg"
$splashGUI = GUICreate("", 500, 375, Default, Default, $WS_POPUPWINDOW)
$splashPIC = GUICtrlCreatePic($img, 0, 0, 500, 375)
GUICtrlSetState($splashPIC, $GUI_DISABLE)
GUISetState()

If _OSBit2() = "64" Then
    $winDir = @WindowsDir & "\syswow64\"
    $winReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\"
    GUICtrlCreateLabel("64 Bit Operating System", 82, 548, 193, 75)
Else
    $winDir = @WindowsDir & "\system32\"
    $winReg = "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\"
    GUICtrlCreateLabel("32 Bit Operating System", 82, 548, 193, 75)
EndIf

Func _OSBit2()
    Local $tOS = DllStructCreate("char[256]")
    Local $aGSWD = DllCall("Kernel32.dll", "int", "GetSystemWow64Directory", "ptr", DllStructGetPtr($tOS), "int", 256)
    If IsArray($aGSWD) And DllStructGetData($tOS, 1) Then Return 64
    Return 32
EndFunc ;==>_OSBit2

$CheckADODB = GUICtrlCreateLabel("MySQL Driver:", 120, 240, 300)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 12, 20, 0, "Comic Sans MS")
$sQLDriver = "{MySQL ODBC 3.51 Driver}"
$SQLv = StringMid($sQLDriver, 2, StringLen($sQLDriver) - 2)
$SQLkey = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
$SQLval = RegRead($SQLkey, $SQLv)
If @error Or $SQLval = "" Then
    MsgBox(0, "Error", "No MySQL Connector Found!" & @CRLF & @CRLF & "You need to install the connector.  Reinstall the chat app to do so.")
    Exit
EndIf
$CheckADODB = GUICtrlCreateLabel("Installed", 260, 240, 300)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 12, 20, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x336633)
$ADOtype = ""
$CheckADODB = GUICtrlCreateLabel("ADODB Connection:", 100, 265, 300)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 12, 20, 0, "Comic Sans MS")
$CLSID = RegRead($winReg & "ADODB.Connection\CLSID", "")
If @error = 1 Then
    RegRead($winReg & "ADODB.Connection.2.8\CLSID", "")
    If @error = 1 Then
        MsgBox(0, "Error", "No ADODB.Connections* Exist! Unable to create connection to remote server." & @CRLF & @CRLF & "You may need to reinstall MDAC components, please contact your system administrator!" & @CRLF & @CRLF & "Attempted to locate the following Keys:" & @CRLF & "1. " & $winReg & "ADODB.Connection" & @CRLF & "2. " & $winReg & "ADODB.Connection.2.8")
        Exit
        If @error = 2 Then
            MsgBox(0, "Error", "No ADODB.Connections* Exist! Unable to create connection to remote server." & @CRLF & @CRLF & "You may need to reinstall MDAC components, please contact your system administrator!" & @CRLF & @CRLF & "Attempted to locate the following Keys:" & @CRLF & "1. " & $winReg & "ADODB.Connection" & @CRLF & "2. " & $winReg & "ADODB.Connection.2.8")
            Exit
        EndIf
    EndIf
ElseIf @error = 2 Then
    RegRead($winReg & "ADODB.Connection.2.8\CLSID", "")
    If @error = 1 Then
        MsgBox(0, "Error", "No ADODB.Connections* Exist! Unable to create connection to remote server." & @CRLF & @CRLF & "You may need to reinstall MDAC components, please contact your system administrator!" & @CRLF & @CRLF & "Attempted to locate the following Keys:" & @CRLF & "1. " & $winReg & "ADODB.Connection" & @CRLF & "2. " & $winReg & "ADODB.Connection.2.8")
        Exit
        If @error = 2 Then
            MsgBox(0, "Error", "No ADODB.Connections* Exist! Unable to create connection to remote server." & @CRLF & @CRLF & "You may need to reinstall MDAC components, please contact your system administrator!" & @CRLF & @CRLF & "Attempted to locate the following Keys:" & @CRLF & "1. " & $winReg & "ADODB.Connection" & @CRLF & "2. " & $winReg & "ADODB.Connection.2.8")
            Exit
        EndIf
    Else
        $ADOtype = "2.8"
    EndIf
Else
    If $ADOtype = "2.8" Then
    Else
        $ADOtype = "Standard"
    EndIf
    If $CLSID = "" Then
        MsgBox(0, "Configuration Issue", "Your windows has located the ADODB.Connection* object, but unable to actually locate any software to run it." & @CRLF & @CRLF & "You will need to reinstall your MDAC Components!")
        Exit
    Else
        $CheckADODB = GUICtrlCreateLabel($ADOtype, 260, 265, 300)
        GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetFont(-1, 12, 20, 0, "Comic Sans MS")
        GUICtrlSetColor(-1, 0x336633) 
    EndIf
EndIf
...blah blah blah, rest of code.... blah blah blah......
Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...