Jump to content
Sign in to follow this  
skysel

Query working on SQL server, not within the script

Recommended Posts

skysel

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 by skysel

Share this post


Link to post
Share on other sites
Spiff59

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.

  • Like 1

Share this post


Link to post
Share on other sites
Tripredacus

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.

Share this post


Link to post
Share on other sites
skysel

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 :)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.