Hi Guys,
I'm busy with a script and have decided to call a sproc and return the result to VB.
Here is the sproc:
CREATE PROCEDURE pr_Cleanup
BEGIN TRAN
TRUNCATE TABLE tb_Users
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
RETURN 101
END
TRUNCATE TABLE tb_Excluded
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
RETURN 102
END
COMMIT TRAN
RETURN 0
So now I would like to catch that 0, 101 or 102 value. In VB I have the following:
Set objCommand = CreateObject("ADODB.Command")
Set objParam = CreateObject("ADODB.Parameter")
Set objRSSQL = CreateObject("ADODB.Recordset")
objCommand.ActiveConnection = "Driver={SQL Server}; Server=127.0.0.1; Database=ListOfUsers; UID=test; PWD=test"
objCommand.CommandText = "pr_Cleanup"
objCommand.CommandType = 4
set objRSSQL = objCommand.Execute
' Set objParam = objCommand.CreateParameter("@retVal",2,3,4)
' objCommand.Parameters.Append objParam
intSprocValue = objCommand.Parameters("@retVal").value
msgbox intSprocValue
If I run the above it works fine and truncates the tables. How do I go about catching the 0, 101 or 102 error code returned from SQL? The bold parameter line seems to be the issue.
Thanks
I'm busy with a script and have decided to call a sproc and return the result to VB.
Here is the sproc:
CREATE PROCEDURE pr_Cleanup
BEGIN TRAN
TRUNCATE TABLE tb_Users
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
RETURN 101
END
TRUNCATE TABLE tb_Excluded
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
RETURN 102
END
COMMIT TRAN
RETURN 0
So now I would like to catch that 0, 101 or 102 value. In VB I have the following:
Set objCommand = CreateObject("ADODB.Command")
Set objParam = CreateObject("ADODB.Parameter")
Set objRSSQL = CreateObject("ADODB.Recordset")
objCommand.ActiveConnection = "Driver={SQL Server}; Server=127.0.0.1; Database=ListOfUsers; UID=test; PWD=test"
objCommand.CommandText = "pr_Cleanup"
objCommand.CommandType = 4
set objRSSQL = objCommand.Execute
' Set objParam = objCommand.CreateParameter("@retVal",2,3,4)
' objCommand.Parameters.Append objParam
intSprocValue = objCommand.Parameters("@retVal").value
msgbox intSprocValue
If I run the above it works fine and truncates the tables. How do I go about catching the 0, 101 or 102 error code returned from SQL? The bold parameter line seems to be the issue.
Thanks