Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSSQL script issue...

Status
Not open for further replies.

BigC72

MIS
Oct 15, 2004
69
0
0
US
I'm working on a script that will allow members of our help desk to clear "hung" user sessions in one of our systems. This is normally something I do directly in the systems database and is relatively straightforward. However I'd prefer not to have all the help desk staff digging around in the database so hence the script....Everything is working fine until I try to execute the delete statements...I've verified that the correct UserID is being populated but for some reason the Execute steps are not working...Hoping someone here can tell me where I'm making my mistake(s). Here's the script:

Code:
Option Explicit 

CONST ForAppending = 8

Dim fso
Dim shell
Dim DBServer
Dim cn
Dim rs
Dim cmd
Dim objLogFile
Dim logfile
Dim UserId
Dim UserName
Dim sqlcmd
Dim result
Dim result2
Dim user
Dim WshNetwork 
Dim loopvalue
Dim sqlErrors 
Dim recAffected
Dim ra
Dim fdate
Dim ftime

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = createobject("Wscript.Shell")

DBserver = "10.10.100.10"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open "DRIVER={SQL Server};server="&DBserver&";database=INOW6;uid=**;pwd=*****"
Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = cn
Set sqlErrors = cn.errors
logfile = "\\anh-inowprod\log\Unlocked_users.log"
user = WshNetwork.UserName
set objLogFile = fso.OpenTextFile(logfile, ForAppending, True, True)
fdate = FormatDateTime(Date(),2)
ftime = FormatDateTime(Now(),4)

Do 
EnterUser
result2 = MsgBox("Do you need to unlock any other user sessions?",4,"Unlock other users?")
If result2 = 6 then 
loopvalue = "TRUE"
else loopvalue = "FALSE"
MsgBox "Thank you..."
end if
Loop while loopvalue = "TRUE"

Wscript.Quit

'Subs
'Input MRN values sub					
'===========================================================
Sub EnterUser()
UserName=InputBox ("Enter ImageNow username for user whose session needs to be killed :", "ImageNow Kill User Session" , "username")
result = MsgBox ("You've indicated you wish to kill user "&UserName& "'s session in the ImageNow database, is this correct?", 1, "ATTENTION: PLEASE VERIFY")
If result = 1 then 
rs.Open "select usr_id from in_usr where usr_name = '"&UserName&"'", cn
UserId = rs.GetString
cn.Execute "delete from in_usr_proc_ctrl where usr_id = '"&UserID&"'"
cn.Execute "delete from in_lic_mon where usr_id = '"&UserID&"'"
for each sqlErrors in sqlErrors 
wscript.echo sqlErrors
Next

else 

MsgBox "Removing the user session in ImageNow has been cancelled"
end if
End Sub
'===========================================================
 
Have you tried echoing your cn.execute command so you can see exactly what is being passed in as the command? Also once you echo the cn.execute command, try copying it and try to run it from a command window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top