Jump to content

MSSQL Remote Connection Delete Query


Recommended Posts

Hello, I am trying to write a code to connect to MSSQL to a database called zzz and run a query to find all records with the word lock in a row and delete the whole line i.e. Line 234 name date phone lock. Here is what i have so far.

Cheers

#include <_sql.au3>
$server = "x.x.x.x"
$dbname = "zzz"
$user = "myuser"
$pass = "12345"
Dim $server, $dbname, $user, $pass, $data
_SQLStartup()
_SQLConnect(-1,$server,$dbname,$user,$pass)
$query = "sp_timesheet_check 'test.user'"
$result = _SQLExecute(-1,$data)
_SQLClose()
MsgBox(4096,"",$result)
Link to comment
Share on other sites

Hello, I am trying to write a code to connect to MSSQL to a database called zzz and run a query to find all records with the word lock in a row and delete the whole line i.e. Line 234 name date phone lock. Here is what i have so far.

Cheers

By having Dim after the values are set, you are wiping out your variable contents.

Try this way:

#include <_sql.au3>

Global $server = "x.x.x.x", $dbname = "zzz", $user= "myuser", $pass= "12345", $data

_SQLStartup()
_SQLConnect(-1,$server,$dbname,$user,$pass)
$query = "sp_timesheet_check 'test.user'"
$result = _SQLExecute(-1,$data)
_SQLClose()
MsgBox(4096,"",$result)

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Nice so Global is better to use then Dim?

Try this way:

#include <_sql.au3>

Global $server = "x.x.x.x", $dbname = "zzz", $user= "myuser", $pass= "12345", $data

_SQLStartup()
_SQLConnect(-1,$server,$dbname,$user,$pass)
$query = "sp_timesheet_check 'test.user'"
$result = _SQLExecute(-1,$data)
_SQLClose()
MsgBox(4096,"",$result)

:)

Link to comment
Share on other sites

Nice so Global is better to use then Dim?

Try this way:

#include <_sql.au3>

Global $server = "x.x.x.x", $dbname = "zzz", $user= "myuser", $pass= "12345", $data

_SQLStartup()
_SQLConnect(-1,$server,$dbname,$user,$pass)
$query = "sp_timesheet_check 'test.user'"
$result = _SQLExecute(-1,$data)
_SQLClose()
MsgBox(4096,"",$result)

:)

Dim would have worked as well as Global. The real point was not to declare the variables AGAIN after the values were set.

I try not to use Dim, because it forces me to explicitly think about Global/Local scope, which helps me avoid certain stupid errors (or at least avoid repeating them). :)

If you run an AutoIt script with the full debugging turned on, it warns you that Dim is deprecated, meaning explicit Global/Local is preferred, and Dim might go away in some future version.

:party:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

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