Sign in to follow this  
Followers 0
hanwar00

SQL connection help

3 posts in this topic

Greetings,

I am new to autoit and currently working on a project to automate querying data from a SQL server and sending that to another software to generate a PDF file. i've been spending some time reading fourms and wrote a script to connect to my sql server using the mysql.au3 UDF. My understanding is inorder to use a UDF i just download the script and use it with include

#include <mysql.au3>

$sUsername = "xxxxxxx"

$sPassword = ""

$sDatabase = "xxxxxxxxx"

$sServer = "xxxxxxxx"

$sDriver = "SQL Server"

$iPort= 1433

$sql=_MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver, $iPort)

if $sql = 0 Then

MsgBox(1,"Connection to Sql Server", "Did not connect")

Else

MsgBox(1,"Connection to Sql Server", "connected")

EndIf

_MySQLEnd($sql)

good news my code is fine and executes without a problem, bad news _MySQLConnect function is returning a 0 meaning is not connection and i am unsure to why its not connecting. If anyone can help me out and point me in the write direction will greatly appreciate it. some information about my sql database (Microsoft SQL Server ODBC Driver Version 06.01.7601)

hanwar00

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You'll need to use ADODB directly, to connect to sql server...like:

$oADODB = ObjCreate("ADODB.Connection")
$oADODB.Open ("Driver={SQL Server};Server=53.90.111.22;Database=crm_user;Uid=cos_user;Pwd=1q2w3e4r5t")

The mysql functions will probably not work for you (please correct me if wrong)

I use this:...pass in the connection string, and the SQL query...it returns the results:

Func WGe_SQLStatement($sCallersConnectionString, $sCallersSQLStatement) ; Perform a SQL Query
 $ado = ObjCreate("ADODB.Connection")
 If @error = 1 Then
  Return False
 EndIf
 $adors = ObjCreate("ADODB.RecordSet")
 If @error = 1 Then
  Return False
 EndIf
 $ado.Open($sCallersConnectionString)
 $adors.Open($sCallersSQLStatement, $ado)
 ; Only get records if there are records to receive
 If $adors.Fields.Count > 0 Then
  Dim $aReturn[1][1]
  $iField = 0
  ; Create the First record of the array with the Field names
  For $Field In $adors.Fields
   ReDim $aReturn[1][$iField + 1]
   $aReturn[0][$iField] = $Field.name
   $iField += 1
  Next
  $iRow = 1
  While Not $adors.EOF
   $iField = 0
   For $Field In $adors.Fields
    $sValue = $adors.Fields($Field.name).value
    ReDim $aReturn[$iRow + 1][UBound($aReturn, 2)]
    $aReturn[$iRow][$iField] = $sValue
    ;Var_SetLogAndActOnState ( 2, 2, "SqlAndSubmitExtRpt()", "Submitted data fro patient#=[" & $iPatient & "]; MRN=[" & $sPID & "]; PatientName=[" & $sLast & " ," & $sFirst & "].", False, False)
    $iField += 1
   Next
   $adors.MoveNext
   $iRow += 1
  WEnd
  ; Close the recordset
  $adors.Close
  $adors = 0
 Else
  $aReturn = True
 EndIf
 ; Close ADODB connection
 $ado.Close
 $ado = 0
 If IsArray($aReturn) Then
  If UBound($aReturn) > 1 Then
   Return $aReturn
  EndIf
 EndIf
 Return True
EndFunc   ;==>WGe_SQLStatement
Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

$oADODB.Open ("Driver={SQL Server};Server=53.90.111.22;Database=crm_user;Uid=cos_user;Pwd=1q2w3e4r5t")

for the line of code above, the server paramter can you use the server name or does it have to be the server IP address?

Share this post


Link to post
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
Sign in to follow this  
Followers 0