ich benutze für die verbindung zu sql 2000 und sql 2008 diese Funktionen:
Spoiler anzeigen
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1 (beta)
; Language: English
; Description: Functions to handle SQL databases.
; Author Chris Lambert
; ------------------------------------------------------------------------------
;#include-once
[/autoit] [autoit][/autoit] [autoit]Func _DisplayError($vText)
MsgBox(0 + 16 + 262144, "SQL Error", $vText)
EndFunc ;==>_DisplayError
Func _SQLRegisterErrorHandler($Func = "_SQLErrFunc")
If ObjEvent("AutoIt.Error") = "" Then $MSSQLObjErr = ObjEvent("AutoIt.Error", $Func)
EndFunc ;==>_SQLRegisterErrorHandler
Func _SQLUnRegisterErrorHandler()
$MSSQLObjErr = ""
EndFunc ;==>_SQLUnRegisterErrorHandler
Func _SQLStartup()
Dim $SQLErr
$adCN = ObjCreate("ADODB.Connection") ;<==Create SQL connection
If IsObj($adCN) Then
$sqlLastConnection = $adCN
Return $adCN
Else
Return SetError(1, 0, 0)
EndIf
EndFunc ;==>_SQLStartup
Func _SQLConnect($ConHandle, $server, $db, $username, $password)
Dim $SQLErr
If $ConHandle = -1 Then $ConHandle = $sqlLastConnection
$ConHandle.Open("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";") ;<==Connect with required credentials
If Not @error Then Return 1
Return SetError(1, 0, 0)
EndFunc ;==>_SQLConnect
Func _SQLClose($ConHandle = -1)
If $ConHandle = -1 Then $ConHandle = $sqlLastConnection
$ConHandle.Close
EndFunc ;==>_SQLClose
Func _SQLExecute($ConHandle = -1, $query = "")
Dim $SQLErr
Local $ret
If $ConHandle = -1 Then $ConHandle = $sqlLastConnection
$ret = $ConHandle.Execute($query)
If @error Then Return SetError(1, 0, 0)
Return $ret
EndFunc ;==>_SQLExecute
Func _SQLGetDataAsString($objquery, $ReturnColumnNames = 1, $delim = "|")
If Not IsObj($objquery) Then
$SQLErr = "Data passed is an invalid object"
Return SetError(1, 0, 0)
EndIf
Dim $ret
Local $i
With $objquery
If $ReturnColumnNames Then
For $i = 0 To .Fields.Count - 1 ;get the column names and put into 0 array element
$ret &= .Fields($i).Name & $delim
Next
If StringRight($ret, 1) = $delim Then $ret = StringTrimRight($ret, 1)
$ret &= @CRLF
EndIf
While Not .EOF
For $i = 0 To .Fields.Count - 1
$ret &= .Fields($i).Value & $delim
Next
If StringRight($ret, 1) = $delim Then $ret = StringTrimRight($ret, 1)
$ret &= @CRLF
.MoveNext; Move to next row
WEnd
EndWith
Return $ret
EndFunc ;==>_SQLGetDataAsString
Func _SQLGetData2D($objquery, $ReturnColumnNames = 1)
[/autoit] [autoit][/autoit] [autoit]If Not IsObj($objquery) Then
$SQLErr = "Data passed is an invalid object"
Return SetError(1, 0, 0)
EndIf
Dim $ret
Dim $SQLErr
Local $i, $aTmp
With $objquery
[/autoit] [autoit][/autoit] [autoit]$ret = .GetRows()
[/autoit] [autoit][/autoit] [autoit]If IsArray($ret) Then
$Dims = UBound($ret, 2)
$Rows = UBound($ret)
If $ReturnColumnNames Then
[/autoit] [autoit][/autoit] [autoit]ReDim $ret[$Rows + 1][$Dims];Adjust the array to fit the column names and move all data down 1 row
[/autoit] [autoit][/autoit] [autoit]For $x = $Rows To 1 Step -1
For $y = 0 To $Dims - 1
$ret[$x][$y] = $ret[$x - 1][$y]
Next
Next
;Add the coloumn names
For $i = 0 To $Dims - 1 ;get the column names and put into 0 array element
$ret[0][$i] = .Fields($i).Name
Next
EndIf;$ReturnColumnNames
Else
SetError(2)
$SQLErr = "Unable to retreive data"
EndIf;IsArray()
;Old method not used anymore but left in commented out until the new method is proven to have no issues
;While NOT .EOF
; ReDim $ret[UBound($ret, 1) + 1][Ubound($ret,2)]; get each row of data
; For $i = 0 To .Fields.Count - 1
; $ret[UBound($ret, 1) - 1][$i] = .Fields($i).Value
; Next
;.MoveNext; Move to next row
;WEnd
EndWith
Return $ret
EndFunc ;==>_SQLGetData2D
;custom error handler
Func _SQLErrFunc()
$SQLErr = $MSSQLObjErr.description
SetError(1)
EndFunc ;==>_SQLErrFunc
[/autoit]damit funktioniert es bei mir einwandfrei.. Das klappt allerdings nur mit ODBC.
Franz