call stored procedure in vb script - stored-procedures

I have created a stored procedure. I tested it in the query analyser like this EXEC test '10/12/2012'. It is OK. But I called it following way in the vb script. It not OK.
InstanceVar = CreateObject("ADODB.Recordset")
InstanceVar.ActiveConnection = ConnVar
InstanceVar.Source = "EXEC Test '" & Date() & "'"
InstanceVar.CursorType = 3
InstanceVar.CursorLocation = 3
InstanceVar.Open()
I have got 80040E14 error. How can I solve it

I realise this is a bit late, but I found this question when looking for a solution to the same problem. I've solved it like this:
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = ConnVar
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Test"
cmd.Parameters.Append(cmd.CreateParameter("#my_date", adVarChar, adParamInput,10))
cmd.Parameters("#my_date") = "10/12/2012"
Set rsResults = Server.CreateObject("ADODB.Recordset")
rsResults.CursorLocation = adUseClient
rsResults.Open cmd,,adOpenForwardOnly,adLockBatchOptimistic
Using CursorLocation = adUseClient means you can navigate the rsResults RecordSet using MoveNext, MoveFirst etc.

Related

Archestra IDE scripting. Start program with Process.StartInfo

I have a script. It's not working. Without UserName and password everything is good. And must the logMessage show me "1" or not because of Secure type? LogMessage shows me just a "System.Security.SecureString" now.
pass = new System.Security.SecureString;
pass.AppendChar("1");
LogMessage(pass);
proc = new System.Diagnostics.Process;
proc.StartInfo.Username = "temp";
proc.StartInfo.Password = pass;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "notepad.exe";
proc.Start();

vbscript and prncnfg.vbs inside?

I have a vbscript to get some informations about the system printing of a remote computer. I can get all the drivers installed, the default network printer name and all my results are send in a outputfile.
I want to get informations about my default network printer by the prncnfg.vbs from the printer server (driver, location, etc.) and send these informations in my outputfile.
Maybe there is an other way to do that ?
Thanks for any suggestions
So, I start to understand the way to do that. But something doesn't work.
First I need to read a file and remove 10 caracters to create my variable, this process works very well:
'Read C:\Temp\DefaultPrinter
Dim shortDefaultPrinter
If objFSO.FileExists("\"& strComputer &"\c$\Temp\DefaultPrinter.txt") then
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("\"& strComputer &"\c$\Temp\DefaultPrinter.txt",1)
DefaultPrinter = objFileToRead.ReadAll()
'remove text \vangogh\
shortDefaultPrinter = Right(DefaultPrinter, Len(DefaultPrinter) - 10)
'MsgBox(shortDefaultPrinter)
objFileToRead.Close
Set objFileToRead = Nothing
Second I want to use my variable shortDefaultPrinter for my query to find the location of my printer:
'Select DefaultPrinter and show location
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName, Location from " _
& " 'LDAP://DC=huge,DC=ad,DC=hcuge,DC=ch' where objectClass='printQueue' and printerName='" & shortDefaultPrinter & "' "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
PrinterLocation = objRecordSet.Fields("Location").Value
MsgBox(PrinterLocation)
objRecordSet.MoveNext
Loop
MsgBox doesn't open, but if I write the name of the printer in place of " & shortDefaultPrinter & ", ex dmed-i714, the process works.
Here I am. If anyone has a suggestion it would be appreciate.

How to read a whole column in Powershell

I'm trying to write a powershell script that will output the contents of a column inside a spreadsheet to a txt file. I don't know powershell but I found and figured out how to get a cell, now I need the whole column. The spreadsheet in question has 8K+ rows. Here is what I have so far:
$SMTPApprovedXLS = "c:\temp\SMTP\SMTPAPPLIST.XLS"
$SheetName = "Active"
$objExcel = New-Object -ComObject Excel.Application
$objExcel.Visible = $False
$Workbook = $objExcel.Workbooks.open($SMTPApprovedXLS)
$Worksheet = $Workbook.sheets.item($SheetName)
$startRow = 4
[pscustomobject][ordered]#{
ApprovedIPs = $Worksheet.Cells.Item(4,$startRow).Value()
}
The column is "D" and should start at row 4.
Thanks in advance.
All you have to do is use a loop to run through all the entries and capture the data. Try this:
$SMTPApprovedXLS = "c:\temp\SMTP\SMTPAPPLIST.XLS"
$SheetName = "Active"
$objExcel = New-Object -ComObject Excel.Application
$objExcel.Visible = $False
$Workbook = $objExcel.Workbooks.open($SMTPApprovedXLS)
$Worksheet = $Workbook.sheets.item($SheetName)
$startRow = 4
$ApprovedIPs = #()
$count = $Worksheet.Cells.Item(65536,4).End(-4162)
for($startRow=4; $startRow -le $count.row; $startRow++)
{
$ApprovedIPs += $Worksheet.Cells.Item($startRow, 4).Value()
}
$ApprovedIPs | Out-File C:\ApprovedIPs.txt
Note that the last line is what creates the txt file with the desired data, where C:\ is the directory and ApprovedIPs is the file name. You can just substitute them for your desired location and name of the file.

Classic ASP - ADO execute Stored Procedure passing in parameters

I am needing to pass parameters into a stored procedure with Classic ASP. I do see some people using the Command object and others NOT using it.
My sproc params are like this:
#RECORD_NUMBER decimal(18,0),
#ErrorType nvarchar(100),
#INSURANCE_CODE smallint,
#CompanyId int,
#INS_ID_NUM nchar(22)
Then I'm trying to do this:
Dim conn, rsSet,rsString, cmd
Dim RN,ET,IC,CI,IIN
RN = Request.Form("Record_Number")
ET = Request.Form("ErrorType")
IC = Request.Form("INSURANCE_CODE")
CI = Request.Form("CompanyID")
IIN = Request.Form("INS_ID_NUM")
set conn = server.CreateObject("adodb.connection")
set rsSet = Server.CreateObject ("ADODB.Recordset")
conn.Open Application("conMestamed_Utilities_ConnectionString")
rs_string = "apUpdateBill " & RN &",'" & ET & "'," & IC & "," & CI & ",'" & IIN & "'"
rsSet.Open rsString, conn, adOpenForwardOnly,, adCmdText
(I don't need a Recordset, i'm just trying to get it to send in data)
Error:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I have tried Command stuff and I get "precision" errors
Do I "have" to use command object?
e.g.
Set cmd = Server.CreateObject("ADODB.Command")
'Set cmd.ActiveConnection = conn
'cmd.CommandText = "apUpdateBill"
'cmd.CommandType = adCmdStoredProc
'Cmd.Parameters.append Cmd.createParameter("#Record_Number", adDecimal, adParamInput, 18)
'Cmd.Parameters("#Record_Number").Precision = 0
'Cmd.Parameters("#Record_Number").value = Request.Form("Record_Number")
Here is how you would do it, you won't need to create a recordset object since it is an update stored procedure:
'Set the connection
'...............
'Set the command
DIM cmd
SET cmd = Server.CreateObject("ADODB.Command")
SET cmd.ActiveConnection = Conn
'Prepare the stored procedure
cmd.CommandText = "apUpdateBill"
cmd.CommandType = 4 'adCmdStoredProc
cmd.Parameters("#RECORD_NUMBER") = Request.Form("Record_Number")
cmd.Parameters("#ErrorType") = Request.Form("ErrorType")
cmd.Parameters("#INSURANCE_CODE") = Request.Form("INSURANCE_CODE")
cmd.Parameters("#CompanyId") = Request.Form("CompanyID")
cmd.Parameters("#INS_ID_NUM") = Request.Form("INS_ID_NUM")
'Execute the stored procedure
'This returns recordset but you dont need it
cmd.Execute
Conn.Close
SET Conn = Nothing

How to display data on the Datagrid from the dataset using db2 DB

I solved the problem with the data not displaying and have corrected the code below.
I need to populate the dataset with the values returned in a stored procedure in db2. I have written a some code which connected to the DB and seems to execute the SP and am populating the dataset but am not find able to figure out how to display the data from the dataset to the grid. Right now it is blank an no data in the grid.
Imports IBM.Data
Imports IBM.Data.DB2
Imports IBM.Data.DB2.DB2DataReader
'cs is the connection string you create in your application.
Dim conn As DB2Connection = New DB2Connection(cs)
conn.Open()
Dim trans As IDbTransaction = conn.BeginTransaction()
Dim cmd As IDbCommand = conn.CreateCommand()
Dim procName As String = "SP_Name"
cmd.Transaction = trans
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = procName
Dim db2da As New DB2DataAdapter
Dim db2ds As New DataSet
db2da.SelectCommand = cmd
cmd.ExecuteNonQuery()
db2da.Fill(db2ds, "Tab1")
Dim introwcount As Integer = db2ds.Tables("Tab1").Rows.Count
Dim intColumncount As Integer = db2ds.Tables("Tab1").Columns.Count
dgvData.DataSource = db2ds.Tables("Tab1")
Appreciate the help.
Thanks
Can you try a DB2Command instead of IDbTransaction? That's how I know to do it, but your requirements may be different than mine.
Dim conn As DB2Connection = New DB2Connection(cs)
Dim cmd As New DB2Command()
cmd.Connection = conn
cmd.CommandText = procName
cmd.CommandType = CommandType.StoredProcedure
Dim rdr AS DB2DataReader = Nothing
Try
conn.Open()
rdr = cmd.ExecuteReader()
dgvData.DataSource = rdr
dgvData.DataBind()
rdr.Close()
Catch ex As DB2Exception
...
Finally
conn.Close()
End Try

Resources