skysel Posted February 13, 2013 Share Posted February 13, 2013 (edited) So below is the code, I can't figure out why the query won't be executed? Query works fine on SQL server itself (without the variables, but raw data). The connection works, as i've tried simple select from that table. $value1 = InputBox("Sifra", "Vpisi sifro:") $value2 = InputBox("Priimek", "Vpisi priimek:") $value3 = InputBox("Ime", "Vpisi ime:") $value4 = InputBox("Username", "Vpisi username:") $value5 = InputBox("DatumPrihoda", "Datum prihoda (YYYY-MM-DD):") $value6 = InputBox("ID_XX", "Vpisi ID_XX:") $value7 = InputBox("ID_XY", "Vpisi ID_XY:") Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $sqlCon = ObjCreate("ADODB.Connection") $sqlCon.ConnectionString = "driver={SQL Server};SERVER=11.12.13.14;database=TEST;uid=user;pwd=pass" $sqlCon.Open ; status is always 1 which means it successfully connected $status = $sqlCon.State ; request data $strSQL = "INSERT INTO [TEST].[dbo].[testtable]([Sifra],[Priimek],[Ime],[UserName],[DatumPrihod],[ID_XX],[ID_XY]) VALUES ('" & $value1 & "','" & $value2 & "','" & $value3 & "','" & $value4 & "','" & $value5 & "','" & $value6 & "','" & $value7 & "')" $result = $sqlCon.execute ($strSQL) $sqlCon.Close Error displayed in console is (syntax check is OK): C:UsersusernameDesktopScriptssqlquery.au3 (27) : ==> The requested action with this object has failed.: $result = $sqlCon.execute ($strSQL) $result = $sqlCon.execute ($strSQL)^ ERROR Edited February 13, 2013 by skysel Link to comment Share on other sites More sharing options...
Spiff59 Posted February 13, 2013 Share Posted February 13, 2013 Replace your "$result = $sqlCon.execute ($strSQL)" line with a "Msgbox(0,"",$strSQL)" and look over the statement you've built. I t appears to me it is missing a (required) space. Tripredacus 1 Link to comment Share on other sites More sharing options...
Tripredacus Posted February 13, 2013 Share Posted February 13, 2013 Comment out the execute line. Then instead send $strSQL to a MsgBox so you can see exactly what is trying to be executed. Then you can check for syntax or if something is missing. Alternatively you can output it to the console or to a text file. Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
skysel Posted February 13, 2013 Author Share Posted February 13, 2013 So the output: INSERT INTO [TEST].[dbo].[testtable]([Sifra],[Priimek],[Ime],[UserName],[DatumPrihod],[ID_XX],[ID_XY]) VALUES ('1','jest','ti','jestti','2013-02-13','4','8') I noticed, after [testtable] there is no space. Will try if it works (adding space there) tomorrow cause im at home now 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