Sign in to follow this  
Followers 0
JamesDover

MSSQL Remote Connection Delete Query

5 posts in this topic

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)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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)

:)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Cheers :)

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  
Followers 0