October 1, 2018 at 2:11 pm
I've been searching around a LOT, and - although I'm come hairline close - can't seem to quite find how to simply execute a T-SQL stored procedure with a RETURN VALUE, and get that RETURN VALUE - all within the SSIS script task, I'd like to use VB.NET.
I already have code like this:
Dim mConn As OleDb.OleDbConnection = DirectCast(Dts.Connections("connection name").AcquireConnection(Nothing), OleDb.OleDbConnection)
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand()
cmd.Connection = mConn
cmd.CommandType = CommandType.StoredProcedure
Basically, I currently have functional code that executes a stored procedure which ends up inserting a record to a table. I then have a SECOND stored procedure which returns the IDENT_CURRENT from the table in question.
I want to execute and get the value from that SECOND stored procedure, which is:
create procedure [dbo].[procname]
as
begin
declare @identity int
set @identity = IDENT_CURRENT('[dbo].[tablename]')
return @identity
end
October 1, 2018 at 2:26 pm
ipisors 92539 - Monday, October 1, 2018 2:11 PMI've been searching around a LOT, and - although I'm come hairline close - can't seem to quite find how to simply execute a T-SQL stored procedure with a RETURN VALUE, and get that RETURN VALUE - all within the SSIS script task, I'd like to use VB.NET.I already have code like this:
Dim mConn As OleDb.OleDbConnection = DirectCast(Dts.Connections("connection name").AcquireConnection(Nothing), OleDb.OleDbConnection)
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand()
cmd.Connection = mConn
cmd.CommandType = CommandType.StoredProcedureBasically, I currently have functional code that executes a stored procedure which ends up inserting a record to a table. I then have a SECOND stored procedure which returns the IDENT_CURRENT from the table in question.
I want to execute and get the value from that SECOND stored procedure, which is:create procedure [dbo].[procname]
as
begin
declare @identity int
set @identity = IDENT_CURRENT('[dbo].[tablename]')
return @identity
end
You can put 3 commands in the CommandText:
cmd.CommandText = "declare @identity int;exec @identity = [dbo].[procname];select @identity"
Dim identity as int32 = cmd.ExecuteScalar
October 1, 2018 at 3:22 pm
Thank you.
I currently get an SSIS error (pasted below), immediately after my Msgbox raises (and prior to the second Msgbox in the below code)
ERROR:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
CODE: (error occurs after first MsgBox, and prior to second MsgBox), in my real code I have the correct "connectionname":
MsgBox("Next line begins declaration of connections, etc")
Dim mConn As OleDb.OleDbConnection = DirectCast(Dts.Connections("connectionname").AcquireConnection(Nothing), OleDb.OleDbConnection)
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand()
cmd.Connection = mConn
cmd.CommandType = CommandType.StoredProcedure
MsgBox("Next line is beginning of text stream open")
October 1, 2018 at 3:24 pm
(Note - my connection manager pictured below)
October 1, 2018 at 3:26 pm
I should also say that my OLE DB connection's actual name is ... well, I left it the way it defaulted to, which was: server.database
..Is that OK?
(so in my real code, instead of "connectionname", I have the name of the OLEDB connection manager, which happens to be, "server.database")
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy