Jump to content

Recommended Posts

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

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.

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...