AngieWill
asked on
SSIS : call oracle procedure with Error Code and Error Description as parameters
Hi,
I created a dtsx package with on Data Flow Task. I defined a variable vValue in this package.
On the events onError and onTaskFailed, I want to call an oracle procedure with as parameters the system::ErrorCode, the system::ErrorDescription and the variable vValue.
I tried with a 'Execute SQL Task' and with a 'Script Task' but I didn't succeed.
1. First solution with Script Task:
Public Sub Main()
'
' Add your code here
'
Dim oracleConn As OracleClient.OracleConnect ion
Dim oracleCmd As OracleClient.OracleCommand
Dim sqlCmd As String
Dim errNumber As Integer
Dim errDescription As String
Dim errSource As String
GetErrorValues(errNumber, errDescription, errSource)
oracleConn = CType(Dts.Connections("Con n1").Acqui reConnecti on(Nothing ), OracleConnection)
oracleConn.Open()
oracleCmd = New OracleClient.OracleCommand ()
oracleCmd.Connection = oracleConn
oracleCmd.CommandText = "Procedure1"
oracleCmd.CommandType = CommandType.StoredProcedur e
oracleCmd.Parameters.AddWi thValue("a sPar1", OracleClient.OracleType.Va rChar).Val ue = errSource
oracleCmd.Parameters.AddWi thValue("a sPar2", OracleClient.OracleType.Va rChar).Val ue = Dts.Variables("User::vValu e").Value
oracleCmd.Parameters.AddWi thValue("a lPar3", OracleClient.OracleType.Nu mber).Valu e = errNumber
oracleCmd.Parameters.AddWi thValue("a sPar4", OracleClient.OracleType.Va rChar).Val ue = errDescription
oracleCmd.ExecuteNonQuery( )
Dts.TaskResult = Dts.Results.Failure
End Sub
Private Sub GetErrorValues(ByRef errNumber As Integer, ByRef errDescription As String, ByRef errSource As String)
Try
Dim vars As Variables
Dts.VariableDispenser.Lock ForRead("E rrorCode")
Dts.VariableDispenser.Lock ForRead("E rrorDescri ption")
Dts.VariableDispenser.Lock ForRead("S ourceName" )
Dts.VariableDispenser.GetV ariables(v ars)
Try
errNumber = CType(vars("ErrorCode").Va lue, Integer)
errDescription = vars("ErrorDescription").V alue.ToStr ing()
errSource = vars("SourceName").Value.T oString()
Catch ex As Exception
Throw ex
Finally
vars.Unlock()
End Try
Catch ex As SystemException
Throw ex
End Try
End Sub
2. Second solution:
I don't find the syntax on the SQL statement...
The two solutions should work?
Thanks for your help
I created a dtsx package with on Data Flow Task. I defined a variable vValue in this package.
On the events onError and onTaskFailed, I want to call an oracle procedure with as parameters the system::ErrorCode, the system::ErrorDescription and the variable vValue.
I tried with a 'Execute SQL Task' and with a 'Script Task' but I didn't succeed.
1. First solution with Script Task:
Public Sub Main()
'
' Add your code here
'
Dim oracleConn As OracleClient.OracleConnect
Dim oracleCmd As OracleClient.OracleCommand
Dim sqlCmd As String
Dim errNumber As Integer
Dim errDescription As String
Dim errSource As String
GetErrorValues(errNumber, errDescription, errSource)
oracleConn = CType(Dts.Connections("Con
oracleConn.Open()
oracleCmd = New OracleClient.OracleCommand
oracleCmd.Connection = oracleConn
oracleCmd.CommandText = "Procedure1"
oracleCmd.CommandType = CommandType.StoredProcedur
oracleCmd.Parameters.AddWi
oracleCmd.Parameters.AddWi
oracleCmd.Parameters.AddWi
oracleCmd.Parameters.AddWi
oracleCmd.ExecuteNonQuery(
Dts.TaskResult = Dts.Results.Failure
End Sub
Private Sub GetErrorValues(ByRef errNumber As Integer, ByRef errDescription As String, ByRef errSource As String)
Try
Dim vars As Variables
Dts.VariableDispenser.Lock
Dts.VariableDispenser.Lock
Dts.VariableDispenser.Lock
Dts.VariableDispenser.GetV
Try
errNumber = CType(vars("ErrorCode").Va
errDescription = vars("ErrorDescription").V
errSource = vars("SourceName").Value.T
Catch ex As Exception
Throw ex
Finally
vars.Unlock()
End Try
Catch ex As SystemException
Throw ex
End Try
End Sub
2. Second solution:
I don't find the syntax on the SQL statement...
The two solutions should work?
Thanks for your help
ASKER
I already tried MsgBox(errNumber) but doesn't appear.
When I try MsgBox("toto"),the Message Box appears.
When I try MsgBox("toto"),the Message Box appears.
ASKER
What must I define in Script Task Editor? PrecompileScriptIntoBinary Code, ReadOnlyVariables...?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"I tried with a 'Execute SQL Task' and with a 'Script Task' but I didn't succeed."
Which was the error? In SQL task you should change the connectiontype to ADO.NET
Regards,
Pedro
Which was the error? In SQL task you should change the connectiontype to ADO.NET
Regards,
Pedro
When you try with Exec SQL task, have you got any error? WHat do you mean by didn't succeed?
ASKER
PedroCGD,
what is the syntax? execute or call?
what is the syntax? execute or call?
ASKER
With 'Script Task', I have no error but ErrorCode is empty.
Add a SQL task and open/edit
In the connection type property, set ADO.NET
In the Connection property set the ADO connection.. if not exist, create one to oracle
In the SQL Statment add the SQL statment SELECT... FROM...
helped?
In the connection type property, set ADO.NET
In the Connection property set the ADO connection.. if not exist, create one to oracle
In the SQL Statment add the SQL statment SELECT... FROM...
helped?
ASKER
PedroCGD,
I want to call an oracle procedure with as parameters the System::ErrorCode and the System::ErrorDescription.
I want to call an oracle procedure with as parameters the System::ErrorCode and the System::ErrorDescription.
ASKER
reza_rad,
I become this error:
Failed to lock varaiable "ErrorCode" for read access with error 0xC0010001 "The variable cannot found. This occurs when an attempt is made to retrive a variable from the variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created."
I will try to include the Data Flow Task in one container.
I become this error:
Failed to lock varaiable "ErrorCode" for read access with error 0xC0010001 "The variable cannot found. This occurs when an attempt is made to retrive a variable from the variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created."
I will try to include the Data Flow Task in one container.
For this error:
Failed to lock varaiable "ErrorCode" for read access with error 0xC0010001 "The variable cannot found
You need to add the name of variable you are using in the ReadOnlyVariables property or readWriteVariables, depending if you wil read or write on it.
helped?
Failed to lock varaiable "ErrorCode" for read access with error 0xC0010001 "The variable cannot found
You need to add the name of variable you are using in the ReadOnlyVariables property or readWriteVariables, depending if you wil read or write on it.
helped?
so this error means that you must add your variable to ReadOnlyVariables or ReadWriteVariables
ASKER
I added ErrorCode in the ReadOnlyVariables but didn't work.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I add in WriteReadVariables : System::ErrorCode,System:: ErrorDescr iption,Sys tem::Sourc eName
In script :
Dts.VariableDispenser.GetV ariables(v ars)
vars.Count return 0????
In script :
Dts.VariableDispenser.GetV
vars.Count return 0????
Sorry... you are using system variables... the logic it's different.
You want to get the error from the connection that you are trying to make, correct? the error message is stored inside EX exception...
see the attached code and image
Helped?
You want to get the error from the connection that you are trying to make, correct? the error message is stored inside EX exception...
see the attached code and image
Helped?
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Try
'
' Add your code here
'
Dts.TaskResult = Dts.Results.Success
Catch ex As Exception
'use EX exception
MsgBox(ex.InnerException)
MsgBox(ex.Message)
'Use SSIS log error events
Dts.TaskResult = Dts.Results.Failure
Dts.Events.FireError(0, "myError", "MyDesc", "", 0)
End Try
End Sub
End Class
ScriptTask.JPG
ASKER
Thanks
But I don't understand.
I want only in my package to catch all errors and save these errors in the database. For this, I want to call an oracle procedure.
I try your script for the OnError event of the DataFlowTask.
In another script task, I do manually an error but this event is not called.
I think I try to find another solution.
But I don't understand.
I want only in my package to catch all errors and save these errors in the database. For this, I want to call an oracle procedure.
I try your script for the OnError event of the DataFlowTask.
In another script task, I do manually an error but this event is not called.
I think I try to find another solution.
ASKER
Sorry the OnError script is called but without exception
Sorry, but you didnt clarify your issues.
You want to save in Oracle each time occur an error?! Did you tried SSIS Logging?!
If you'll do it manually I sugeest using SSIS EventHandlers
You want to save in Oracle each time occur an error?! Did you tried SSIS Logging?!
If you'll do it manually I sugeest using SSIS EventHandlers
ASKER
Sorry I am new in SSIS.
I want to save in oracle each time an error occurs but the SSIS package should return 'Failure'.
I hope you understand what I want.
Thanks.
I want to save in oracle each time an error occurs but the SSIS package should return 'Failure'.
I hope you understand what I want.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Finally, I catch all errors in the application which calls the dtsx package.
Thanks for your help.
Thanks for your help.
Then try to call the SPROC by passing parameters(via these variables) using Execute SQL task