Jump to content

Recommended Posts

Posted

func servcheck()
    TCPStartUp()
    Opt("TCPTimeout",10000) 
    $sServer = GUICtrlRead($inpserv)
    If $sServer = 'localhost' Then
        $sServer = '127.0.0.1'
        EndIf
    $socket = TCPConnect($sServer, 1433)
    If $socket = -1 Then
        MsgBox(16,"Внимание!!!!","Няма връзка със СЪРВЪРА: "& $sServer&@lf&"Проверете дали има интернет или локална връзка до сървъра."&@lf&"Проверете дали TCP порт 1433 е отворен.")
    Else
        MsgBox(64,"Информация","Има Връзка до сървъра!!!")
    EndIf
    MsgBox(0,"test"," " & _GUICtrlEdit_GetText($inppass))
    $sDatabase = GUICtrlRead($inpbase)
    $sUsername = GUICtrlRead($inpusr) 
    $sPassword = _GUICtrlEdit_GetText($inppass)
    $sDriver = "{SQL Server}"
    $conn = ObjCreate("ADODB.Connection")
    $DSN =("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")
    
    If IsObj($conn.open($DSN)) Then
    MsgBox(64,"test", "con open")
    Else
    MsgBox(16, "Error", "Failed to create conn.")
    EndIf
    
        
EndFunc

when i type wrong password for sql connection the autoit exits whit error =>

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\user\Desktop\autoit comport\testsql.au3"   
C:\Documents and Settings\user\Desktop\autoit comport\testsql.au3 (71) : ==> The requested action with this object has failed.:
If IsObj($conn.open($DSN)) Then
If IsObj($conn.open($DSN)^ ERROR
>Exit code: 1   Time: 3.966

i need to test the connection to the database to be shure there is connection before i send some queries.

Posted

Try this:

$conn.open($DSN)
     If @error Then 
           ; Handle it Here
    EndIf
       ; Or Here
     If $conn.State = 1 Then; adoStateOpen, adoStateClosed = 0
            MsgBox(64,"test", "con open")
    Else
            MsgBox(16, "Error", "Failed to create conn.")
    EndIf

func servcheck()
    TCPStartUp()
    Opt("TCPTimeout",10000) 
    $sServer = GUICtrlRead($inpserv)
    If $sServer = 'localhost' Then
        $sServer = '127.0.0.1'
        EndIf
    $socket = TCPConnect($sServer, 1433)
    If $socket = -1 Then
        MsgBox(16,"Внимание!!!!","Няма връзка със СЪРВЪРА: "& $sServer&@lf&"Проверете дали има интернет или локална връзка до сървъра."&@lf&"Проверете дали TCP порт 1433 е отворен.")
    Else
        MsgBox(64,"Информация","Има Връзка до сървъра!!!")
    EndIf
    MsgBox(0,"test"," " & _GUICtrlEdit_GetText($inppass))
    $sDatabase = GUICtrlRead($inpbase)
    $sUsername = GUICtrlRead($inpusr) 
    $sPassword = _GUICtrlEdit_GetText($inppass)
    $sDriver = "{SQL Server}"
    $conn = ObjCreate("ADODB.Connection")
    $DSN =("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")
    
    If IsObj($conn.open($DSN)) Then
    MsgBox(64,"test", "con open")
    Else
    MsgBox(16, "Error", "Failed to create conn.")
    EndIf
    
        
EndFunc

when i type wrong password for sql connection the autoit exits whit error =>

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\user\Desktop\autoit comport\testsql.au3"   
C:\Documents and Settings\user\Desktop\autoit comport\testsql.au3 (71) : ==> The requested action with this object has failed.:
If IsObj($conn.open($DSN)) Then
If IsObj($conn.open($DSN)^ ERROR
>Exit code: 1   Time: 3.966

i need to test the connection to the database to be shure there is connection before i send some queries.

Posted

Try this:

$conn.open($DSN)
     If @error Then 
          ; Handle it Here
    EndIf
      ; Or Here
     If $conn.State = 1 Then; adoStateOpen, adoStateClosed = 0
            MsgBox(64,"test", "con open")
    Else
            MsgBox(16, "Error", "Failed to create conn.")
    EndIf
i figured out already but 10x for the help

i found it in the forum and adjust it to my code

.......Global $sCOMErrMsg=""
$oCOMError = ObjEvent("AutoIt.Error","_COMErrHandler");

.......
If @error Then
    MsgBox(16,"Внимание!!!","Няма връзка с базата данни проверете паролата си и опитайте отново.");
    Else
    MsgBox(64,"Инфотмация", "Има връзка с базата данни.")
    EndIf

............
Func _COMErrHandler()
   $sCOMErrMsg=hex($oCOMError.number,8) & ":" & $oCOMError.description
   SetError(1)            
Endfunc
Posted

Hello,

It appears you have found your answer to your question.

Please take the time to edit your thread title with [RESOLVED] so others know that is it resolved.

You can do this by scrolling to the top of your thread, clicking EDIT and then Full Edit and adding: "[RESOLVED]"

to the front of your thread title.

Thanks for your cooperation.

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
  • Recently Browsing   0 members

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