Classic ASP - ADO execute Stored Procedure passing in parameters - stored-procedures

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

Related

ADO adLockBatchOptimistic allows updates on modified records

I'm begging for help, since I'm too stupid.
What I do:
Open connection to Access DB
Download Table to a Recordset
Disconnect the RecordSet
Update a record
Update the same record in DB (by another user)
Connect RecordSet back to DB
UpdateBatch affected record
Yesterday it was throwing an error that the record has been modified in the meantime.
Today it's updating the record without any issues.
I would bet my arm I haven't changed anything...
I open the recordset with following settings (first set them, then open):
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
I beg everyone for help
Example Code:
Dim DB_FOLDER_PATH As String
Dim DB_FILE_NAME As String
Dim DB_FILE_PATH As String
Dim CONNECTION As ADODB.CONNECTION
Dim CONNECTION_STRING As String
Dim QUERY_STRING As String
Dim tmp_RS As ADODB.Recordset
Dim tmp_RS2 As ADODB.Recordset
DB_FOLDER_PATH = "\\XXXXX\userdata\XXXXX\home\Documents\Data Base\"
DB_FILE_NAME = "TEST"
DB_FILE_PATH = DB_FOLDER_PATH & DB_FILE_NAME & ".accdb"
Set CONNECTION = New ADODB.CONNECTION
CONNECTION_STRING = "Provider=Microsoft.ACE.OLEDB.12.0" & ";" & "Data Source=" & DB_FILE_PATH & ";" & "Persist Security Info=False"
CONNECTION.Open CONNECTION_STRING
QUERY_STRING = "SELECT" & " " & "*" & " FROM [" & "DATA" & "]" & ";"
Set tmp_RS = New ADODB.Recordset
With tmp_RS
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open QUERY_STRING, CONNECTION
.ActiveConnection = Nothing
End With
Set tmp_RS2 = New ADODB.Recordset
With tmp_RS2
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Open QUERY_STRING, CONNECTION
.ActiveConnection = Nothing
End With
With tmp_RS
.Fields("FIELD_LONG_TEXT_PLAIN").Value = "ABC"
.Update
.ActiveConnection = CONNECTION
.UpdateBatch
End With
With tmp_RS2
.Fields("FIELD_LONG_TEXT_PLAIN").Value = "ZXC"
.Update
.ActiveConnection = CONNECTION
.UpdateBatch
End With
Best Regards,
Michal

Stored procedure with a return parameter - "ODBC driver does not support the requested properties"?

I have followed the previous code and try to call a stored procedure
ALTER PROCEDURE [dbo].[sp_test]
#in char(5) = ' ',
#out smallint = 0 output
AS
BEGIN
SET NOCOUNT ON;
SET #out = 100
END
Then in the VB6, i try to request this stored procedure by below
strConn = "Select * from TBL where 1=2"
Set rsCmd = objCCS.ExecuteStatement(strConn, adUseServer, adOpenDynamic, adLockBatchOptimistic)
Dim rdoqry_data2 As ADODB.Command
Set rdoqry_data2 = CreateObject("Adodb.command")
Set rdoqry_data2 = rsCmd.ActiveCommand
rdoqry_data2.CommandType = adCmdStoredProc
rdoqry_data2.CommandText = "sp_test"
rdoqry_data2(0).Direction = adParamReturnValue
rdoqry_data2(1).Direction = adParamInput
rdoqry_data2(2).Direction = adParamOutput
rdoqry_data2(2).Type = adSmallInt
rdoqry_data2(1) = "123"
rdoqry_data2.Execute
But it flow an exception ODBC driver does not support the requested properties.
Can anyone find the problem?
Thanks.
Where exactly does the exception appear? I guess the exception is the result of calling the procedure sp_test and not the result of executing objCCS.ExecuteStatement, right?
My approach to call the stored procedure sp_test from VB6 would be:
Dim rdoqry_data2 As ADODB.Command
Set rdoqry_data2 = New ADODB.Command
With rdoqry_data2
Set .ActiveConnection = (your connection object)
.Parameters.Append rdoqry_data2.CreateParameter("#in", adVarchar, adParamInput, 5, "123")
.Parameters.Append rdoqry_data2.CreateParameter("#out", adSmallInt, adParamOutput, 2)
.CommandType = adCmdStoredProc
.CommandText = "sp_test"
.Execute
End With
First you have to create the command object and assign the connection object to it. In this case you need two parameter objects. First parameter is an input parameter with a maximum size of 5 bytes (char(5)) and the content "123". Second parameter is an output parameter with a max. size of 2 bytes (smallint). Finally you have to tell the command object to call a stored procedure with the name "sp_test".
Does this work for you?

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

Jython ziclix JDBC, get stored procedure return value - Chained Transaction Mode

I am trying to get value returned by a Sybase user-defined stored procedure, following is the code snippet.
from com.ziclix.python.sql import zxJDBC
def callStoredProc(conn, procName, *args):
conn.execute("USE DB")
sql = """DECLARE #ret int
EXEC #ret = %s %s
SELECT #ret""" % (procName, ','.join(['?'] * len(args)))
return int(conn.execute(sql, args).fetchone()[0])
jdbc_url = "jdbc:sybase:Tds:192.168.1.100:3397/stagingdb"
username = "sa"
password = ""
driver = "com.sybase.jdbc4.jdbc.SybDriver"
conn = zxJDBC.connect(jdbc_url, username, password, driver)
cursor = conn.cursor()
print callStoredProc(cursor, "usp_find", "Apples" )
But when I run script, it says;
zxJDBC.Error: Stored procedure 'usp_find' may be run only in unchained transaction mode. The 'SET CHAINED OFF' command will cause the current session to use unchained transaction mode. [SQLCode: 7713], [SQLState: ZZZZZ]
However, if I add conn.execute("SET CHAINED OFF") in callStoredProc() it return None.
Is there any way to get returned value off sybase stored procedure in Jython/Python?
I do not know how to change chainde transation mode, but I want you to try "clear" JDBC and CallableStatemet. Such code looks like (I do not have Sybase so I cannot test it):
db = DriverManager.getConnection(db_url, usr, passwd)
proc = db.prepareCall("{ ? = call usp_find(?) }");
proc.registerOutParameter(1, Types.INTEGER)
proc.setString(2, "Apples");
proc.execute();
r = proc.getInt(1)
print('result: %d' % (r))

call stored procedure in vb script

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.

Resources