lyledg Posted February 21, 2007 Share Posted February 21, 2007 Hi GuysI am trying to connect to SQL 2005 Standard via Autoit and not sure how to do it.I have searched the forums but knowing that SQL 2005 uses a "SQL native Client" I am not sure this can be done?has anyone attempted this, and if so would they mind providing some code around it?I have searched on www.connectionstrings.com and found the connection string to be:http://www.connectionstrings.com/?carrier=sqlserver2005Dim $sqlCon, $sqlprompt ;Connect into the database on launch of the application $sqlCon = ObjCreate("ADODB.Connection") $sqlCon.Open("Provider=SQLNCLI;Server=<SERVERNAME>;Database=<DBNAME>;Uid=<USERNAME>;Pwd=$<PSWD>;") if @error Then MsgBox(0, "ERROR", "Failed to connect to the database") Exit Else MsgBox(0, "Success!", "Connection to database successful!") EndIfWill this work? Link to comment Share on other sites More sharing options...
lyledg Posted February 22, 2007 Author Share Posted February 22, 2007 Bump ^ Link to comment Share on other sites More sharing options...
Eusebio Posted February 23, 2007 Share Posted February 23, 2007 expandcollapse popupFunc _BDConnect($bdName="",$Server="",$mode=3,$connectionTimeOut=0,$commandTimeOut=0) ;Cadenas de conexión: http://www.connectionstrings.com/ Local $xCNN,$cConn if $Server="" Then if StringUpper(StringRight ($bdName,4))<>".MDB" Then $bdName=$bdName & ".MDB" EndIf $cConn="PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & $bdName Else $cConn="Provider=sqloledb;Server=" & $Server & ";Initial Catalog=" & $bdName & ";integrated security=SSPI;persist security info=False;" ;$cConn="Driver={SQL Server};Server=" & $Server & ";Database=" & $bdName & ";Trusted_Connection=Yes;" ;$cConn="Driver={SQL Server};Server=" & $Server & "Database=" & $bdName & ";Uid=sa;Pwd=MyPassword;" ;$cConn="Provider=sqloledb;Data Source=192.168.1.10,1433;Network Library=DBMSSOCN;Initial Catalog=" & $bdName & ";User ID=sa;Password=MyPassword;" ;$cConn="Data Source=" & $Server & ";Initial Catalog=" & $bdName & ";Integrated Security=SSPI;" EndIf $xCNN=Objcreate("ADODB.Connection") $xCNN.mode=$mode ;(2=adModeRead; 3=adModeReadWrite; 12=adModeShareExcludive) $xCNN.connectiontimeout=$connectionTimeOut $xCNN.commandtimeout=$commandTimeOut $xCNN.Open($cConn) Return $xCNN EndFunc Func _BDCloseConnexion(ByRef $xCNN) ;State ; adStateClosed =0 ; adStateOpen =1 ; adStateConnecting=2 if $xCNN.state=1 then $xCNN.close $xCNN=0 EndIf EndFunc Func _BDCloseRecordSet(byref $RS) ;State ; adStateClosed =0 ; adStateOpen =1 ; adStateConnecting=2 if $RS.state=1 then $RS.close $RS=0 EndIf EndFunc Func _BDSQLQuery(ByRef $xCNN,$strSQL,$cursorLocation=3,$cursorType=3,$lockType=3) ;CursorLocation ; adUseServer =2 ; adUseClient =3 ;CursorType ; adOpenForwardOnly =0 ; adOpenKeyset =1 ; adOpenDynamic =2 ; adOpenStatic =3 ;LockType ; adLockReadOnly =1 ; adLockPessimistic =2 ; adLockOptimistic =3 ; adLockBatchOptimistic=4 Local $miRS $miRS=ObjCreate("ADODB.Recordset") $miRS.cursorLocation=$cursorLocation $miRS.cursortype=$cursorType $miRS.locktype=$lockType $miRS.activeconnection=$xCNN $miRS.source=$strSQL $miRS.open Return ($miRS) EndFunc Func _getTables(ByRef $xCNN) Local $adoRs,$cCad $cCad="" $adoRs=Objcreate("ADODB.Recordset") $adoRs = $xCNN.OpenSchema (20) while not $adoRs.eof() if stringmid($adoRs("TABLE_NAME").value,1,4)<>"MSys" Then $cCad=$cCad & $adoRs("TABLE_NAME").value & "|" EndIf $adoRs.movenext() wend $adoRs.close() $adoRs=0 Return $cCad EndFunc Func _BDQuote($str) Return (Quote = "'" & $str & "'") EndFunc WhoIsYouTube Video downloaderSoundex - SoundexEx - Levenshtein Distance (algorithms)[font="Arial"]I3osé[/font][font="Arial"]AutoIT[/font] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now