BarryCrosby
Technical User
Hi,
I have the following script to connect to a database to check a value that has been submitted via an input box. The three scenarios are:
1) A single match exists
2) Duplicate matches exist
3) No matches exist
However when I am trying to test scenario all I get is a record count of -1?????
Any help would be much appreciated. It's been a little while since I dabbled with VBS so I think I am out of practice. Below is the script I have so far.
'Declare the parameters used in this VBScript.
Dim sSQL
Dim sServer
Dim sDB
Dim slogin
Dim sPwd
Dim oFso, oExec, rc
Dim oRs
Dim vRows
Dim iFieldCount
Dim iRecordCount
Dim EventRef
Dim EventType
Dim EventId
Dim strReqDateTime
Dim FilePrefix
Dim ImportFileName
Dim fname
fname=Inputbox("Enter the affected users login:")
strReqDateTime = Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & Right("0" & Hour(Now),2) & Right("0" & Minute(Now),2) & Right("0" & second(Now),2)
'Set the Parameters in order to Connect to the database
sSQL = "SQLServer"
sServer = "127.0.0.1\SQLEXPRESS"
sDB = "aweb75demo"
sLogin = "barry"
sPwd = "barry"
FilePrefix = "C:\\Imports\\"
ImportFileName = FilePrefix & "FTF_newcall_" & strReqDateTime & ".imp"
'Create the connection to the database and open a recordset.
Set oCn = CreateObject( "ADODB.Connection" )
Set oRs = CreateObject( "ADODB.Recordset" )
'create the connection to a file to create for import
'construct the connectionstring
oCn.ConnectionString = "PROVIDER=SQLOLEDB" & _
";SERVER=" & sServer & _
";UID=" & sLogin & _
";PWD=" & sPwd & _
";DATABASE=" & sDB & " "
'...and open the connection to the database
oCn.Open
test = 1
'Create the SQL and execute
SQLLINE = "SELECT usr.usr_sc FROM usr WHERE usr_sc = '" & ucase(fname) & "'"
msgbox(SQLLINE)
Set oRs = oCn.Execute(SQLLINE)
'oRs.Movefirst
msgbox("test")
if not oRs.EOF then
If oRs.Fields(0).Value = ucase(fname) Then
msgbox("There are records")
msgbox(oRs.Fields(0).Value)
msgbox oRs.Fields("USR_SC").Value
msgbox oRs.recordcount
end if
else
msgbox("There are no matching records")
msgbox oRs.recordcount
end if
if not oRs.EOF then
Call WriteAIMFile()
'Call ACLI()
oRs.Close
'Clear SSQL and recordset
Set oRs=Nothing
oCn.Close
Set objConnection=Nothing
Set oFso=Nothing
wscript.quit
else
fname = inputbox("You have entered an incorrect login, please enter the correct affected users login:")
if not oRs.EOF then
Call WriteAIMFile()
'Call ACLI()
oRs.Close
'Clear SSQL and recordset
Set oRs=Nothing
oCn.Close
Set objConnection=Nothing
Set oFso=Nothing
wscript.quit
else
Msgbox("You have entered an incorrect login twice. Please click on the toolbar to run this script again to try again.")
End if
End if
Sub WriteAIMFile()
Set oFso = CreateObject("Scripting.FileSystemObject")
Set newevent = oFso.CreateTextFile(ImportFileName, True)
newevent.writeline("@*@AFFECTED@*@:"&ucase(fname))
newevent.writeline("@*@ITEM@*@:AD SECURITY")
newevent.writeline("@*@CATEGORY@*@:ACCOUNT LOCKOUT")
newevent.writeline("1st Time Fix")
newevent.writeline("Please unlock network account")
newevent.writeline("User ID: "&ucase(fname))
newevent.writeline("|END OF INCIDENT|")
newevent.close
Set fso=Nothing
End Sub
Sub ACLI()
'msgbox("Launch ACLI")
'Then Proceed with ACLI
Set WshShell = CreateObject("WScript.Shell")
CommandLine = """C:\Program Files\assyst Enterprise 8.0\acli.exe"""
CommandLine = CommandLine &" -v:" &sSQL &" -h:"&sServer &" -d:" &sDB &" -u:" &slogin &" -p:"&sPwd
CommandLine = CommandLine & " -f:"""& ImportFileName & """ -t -ep:ANET -ap:ANET -ui:n"
WshShell.Exec(CommandLine)
'msgbox(commandline)
End Sub
I have the following script to connect to a database to check a value that has been submitted via an input box. The three scenarios are:
1) A single match exists
2) Duplicate matches exist
3) No matches exist
However when I am trying to test scenario all I get is a record count of -1?????
Any help would be much appreciated. It's been a little while since I dabbled with VBS so I think I am out of practice. Below is the script I have so far.
'Declare the parameters used in this VBScript.
Dim sSQL
Dim sServer
Dim sDB
Dim slogin
Dim sPwd
Dim oFso, oExec, rc
Dim oRs
Dim vRows
Dim iFieldCount
Dim iRecordCount
Dim EventRef
Dim EventType
Dim EventId
Dim strReqDateTime
Dim FilePrefix
Dim ImportFileName
Dim fname
fname=Inputbox("Enter the affected users login:")
strReqDateTime = Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & Right("0" & Hour(Now),2) & Right("0" & Minute(Now),2) & Right("0" & second(Now),2)
'Set the Parameters in order to Connect to the database
sSQL = "SQLServer"
sServer = "127.0.0.1\SQLEXPRESS"
sDB = "aweb75demo"
sLogin = "barry"
sPwd = "barry"
FilePrefix = "C:\\Imports\\"
ImportFileName = FilePrefix & "FTF_newcall_" & strReqDateTime & ".imp"
'Create the connection to the database and open a recordset.
Set oCn = CreateObject( "ADODB.Connection" )
Set oRs = CreateObject( "ADODB.Recordset" )
'create the connection to a file to create for import
'construct the connectionstring
oCn.ConnectionString = "PROVIDER=SQLOLEDB" & _
";SERVER=" & sServer & _
";UID=" & sLogin & _
";PWD=" & sPwd & _
";DATABASE=" & sDB & " "
'...and open the connection to the database
oCn.Open
test = 1
'Create the SQL and execute
SQLLINE = "SELECT usr.usr_sc FROM usr WHERE usr_sc = '" & ucase(fname) & "'"
msgbox(SQLLINE)
Set oRs = oCn.Execute(SQLLINE)
'oRs.Movefirst
msgbox("test")
if not oRs.EOF then
If oRs.Fields(0).Value = ucase(fname) Then
msgbox("There are records")
msgbox(oRs.Fields(0).Value)
msgbox oRs.Fields("USR_SC").Value
msgbox oRs.recordcount
end if
else
msgbox("There are no matching records")
msgbox oRs.recordcount
end if
if not oRs.EOF then
Call WriteAIMFile()
'Call ACLI()
oRs.Close
'Clear SSQL and recordset
Set oRs=Nothing
oCn.Close
Set objConnection=Nothing
Set oFso=Nothing
wscript.quit
else
fname = inputbox("You have entered an incorrect login, please enter the correct affected users login:")
if not oRs.EOF then
Call WriteAIMFile()
'Call ACLI()
oRs.Close
'Clear SSQL and recordset
Set oRs=Nothing
oCn.Close
Set objConnection=Nothing
Set oFso=Nothing
wscript.quit
else
Msgbox("You have entered an incorrect login twice. Please click on the toolbar to run this script again to try again.")
End if
End if
Sub WriteAIMFile()
Set oFso = CreateObject("Scripting.FileSystemObject")
Set newevent = oFso.CreateTextFile(ImportFileName, True)
newevent.writeline("@*@AFFECTED@*@:"&ucase(fname))
newevent.writeline("@*@ITEM@*@:AD SECURITY")
newevent.writeline("@*@CATEGORY@*@:ACCOUNT LOCKOUT")
newevent.writeline("1st Time Fix")
newevent.writeline("Please unlock network account")
newevent.writeline("User ID: "&ucase(fname))
newevent.writeline("|END OF INCIDENT|")
newevent.close
Set fso=Nothing
End Sub
Sub ACLI()
'msgbox("Launch ACLI")
'Then Proceed with ACLI
Set WshShell = CreateObject("WScript.Shell")
CommandLine = """C:\Program Files\assyst Enterprise 8.0\acli.exe"""
CommandLine = CommandLine &" -v:" &sSQL &" -h:"&sServer &" -d:" &sDB &" -u:" &slogin &" -p:"&sPwd
CommandLine = CommandLine & " -f:"""& ImportFileName & """ -t -ep:ANET -ap:ANET -ui:n"
WshShell.Exec(CommandLine)
'msgbox(commandline)
End Sub