Jump to content

adodb.connection


Xand3r
 Share

Recommended Posts

Any ideea why

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)

i get something like this " : -2147352567" (thats the exact number i get every time)

Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Can't say without more code (how you have declared $Objconn, etc.)

Also, use an error handler to report more errors

; Initializes COM handler
$oError = ObjEvent("AutoIt.Error", "ErrHandler")
; You COM object declarations go here....
Global $adoCn = ObjCreate( "ADODB.Connection" )

Func ErrHandler()
  $HexNumber=Hex($oError.number,8)
  Msgbox(0, StringReplace( $oError.windescription, "error", "COM Error #") & $oError.Number, _
            $oError.Description & @CRLF & _
            "Source: "       & @TAB & $oError.source         & @CRLF & _
            "at Line #: " & $oError.ScriptLine & @TAB & _
            "Last DllError: " & @TAB & $oError.lastdllerror   & @CRLF & _
             "Help File: " & @TAB & $oError.helpfile & @TAB & "Context: " & @TAB & $oError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
 ;Exit
Endfunc

Any ideea why

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)

i get something like this " : -2147352567" (thats the exact number i get every time)

Link to comment
Share on other sites

Func _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{MySQL ODBC 5.1 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
    $ObjConn = ObjCreate("ADODB.Connection")
    $Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)
    If @error Then
        SetError(1)
        Return 0
    Else
        Return $ObjConn
    EndIf
EndFunc   ;==>_MySQLConnectoÝ÷ Ù©ÝÚ!j÷ê뢸ZÙ^¯­r¬ºÇ¥zË"Øb±Æ¬y«­¢+ÙÕ¹5åÉÉÕ¹ ¤($ÀÌØí¡á¹Õ´ô!à ÀÌØí½©Éȹ¹ÕµÈ°à¤(%}° ÅÕ½Ðí]¥¹ÑÉÁÑ
=4ÉɽÈÌÌìÌÌìÅÕ½ÐìµÀì
I1µÀì|($$$ÅÕ½ÐíÉȹÍÉ¥ÁÑ¥½¸¥ÌèÅÕ½ÐìµÀìÀÌØí½©ÉȹÍÉ¥ÁÑ¥½¸µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹݥ¹ÍÉ¥ÁÑ¥½¸¥ÌèÅÕ½ÐìµÀìÀÌØí½©Éȹݥ¹ÍÉ¥ÁÑ¥½¸µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ±Íѱ±ÉɽȥÌèÅÕ½ÐìµÀìÀÌØí½©Éȹ±Íѱ±ÉɽȵÀì
I1µÀì|($$$ÅÕ½ÐíÉȹÍÉ¥Áѱ¥¹¥ÌèÅÕ½ÐìµÀìÀÌØí½©ÉȹÍÉ¥Áѱ¥¹µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ¹ÕµÈ¥ÌèÅÕ½ÐìµÀìÀÌØí¡á¹Õ´µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹͽÕÉ¥ÌèÅÕ½ÐìµÀìÀÌØí½©ÉȹͽÕɵÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ¡±Á¥±¥ÌèÅÕ½ÐìµÀìÀÌØí½©Éȹ¡±Á¥±µÀì
I1µÀì|($$$ÅÕ½ÐíÉȹ¡±Á½¹ÑáÐ¥ÌèÅÕ½ÐìµÀìÀÌØí½©Éȹ¡±Á½¹ÑáÐ|($$$°Ð¤(%IÑÕɸÀ)¹Õ¹ìôôÐí5åÉÉÕ¹

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

This formula works for me with Advantage Database Server:

$ADS_Path = "Provider=Advantage OLE DB Provider;Data Source=\\Screamer\MediData\CFC\mwddf.add;User Id=user;Password=password;"
$oADO = ObjCreate("ADODB.Connection")
$oADO.mode = 3;(2=adModeRead; 3=adModeReadWrite; 12=adModeShareExcludive)1
If Not IsObj($oADO) Then MsgBox(1,"error", "! Error")
$oADO.Open($ADS_Path)
If @error Then
    MsgBox(0, "ERROR", "Failed to connect to the database")
    Exit
EndIf

And this one works on Access databases:

$oADO = ObjCreate("ADODB.Connection")
$oADO.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=\\X-Ray\TigerView\Data\tvdata.mdb")
$oRS = ObjCreate("ADODB.Recordset")
$SQL = "Select ORDID FROM Patients where PMSID = '" & $sPatientChart & "';"
$oRS.Open($SQL, $oADO, 1, 3)

I'm not sure if any syntax differences will jump out at you, but those are both working examples using different databases.

Edit: I can say I've left half the parameters shown in the reference manuals out of the code making these connections.

Edited by Spiff59
Link to comment
Share on other sites

I am not sure ultimately what the values on your machine are for $sDriver, $sServer, and $sDatabase, but you could check here for more ideas http://www.autoitscript.com/forum/index.php?showtopic=20814

Func _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{MySQL ODBC 5.1 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
    $ObjConn = ObjCreate("ADODB.Connection")
    $Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)
    If @error Then
        SetError(1)
        Return 0
    Else
        Return $ObjConn
    EndIf
Link to comment
Share on other sites

Hmm, it's supposed to be one quoted parameter passed to the .Open statement me thinks... I don't see any quotes getting wrapped around your entire parameter line?

Hmm, one of my examples is, and one not. Scratch that!

Edited by Spiff59
Link to comment
Share on other sites

crap i edited the first post and accidentaly removed some text :)

so the program works just fine while the mysql server is online... it just does that when it's offline

and i know for certain that it's because of that line because if i put

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)
msgbox(0 , 'test' , @error)oÝ÷ Ú(´J뢳â´ïjXÂ)Ý£ZÙ^Ó4ÓM4ÓFî¶'âv®¶­sf×6v&÷Âb33·FW7Bb33²Âb33c´ö&¦6öæâæ÷VâgV÷C´E$dU#ÒgV÷C²fײb33c·4G&fW"fײgV÷C³µ4U%dU#ÒgV÷C²fײb33c·56W'fW"fײgV÷C³´DD$4SÒgV÷C²fײb33c·4FF&6RfײgV÷C³µTCÒgV÷C²fײb33c·5W6W&æÖRfײgV÷C³µtCÒgV÷C²fײb33c·577v÷&BfײgV÷C³µõ%CÒgV÷C²fײb33c¶÷'BfײgV÷C²¢gV÷C²f×´W'&÷"

i get that weird number

Edited by TheMadman

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Until kinks are worked out, it makes sense to split up parameters/settings into multiple lines like so:

Build Conn. String

$ConnectionString = "Provider=MSDASQL.1;Extended Properties=DRIVER={" & $sDriver & "};";..., + Server/Database etc.
     $adoCn.Properties("Prompt") = 1; adPromptAlways
     $adoCn.ConnectionString = $ConnectionString
     $adoCn.Open

Hmm, it's supposed to be one quoted parameter passed to the .Open statement me thinks... I don't see any quotes getting wrapped around your entire parameter line?

Hmm, one of my examples is, and one not. Scratch that!

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...