Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Execute SQL Task, OLE DB, Stored Procedure, Returns unexpected value upon second run

$
0
0

when debugging SSIS, the "Execute SQL Task" runs a stored procedure and returns the expected value. When running the package a second time, the task returns an unexpected value. When running in VS2012 SQL editor, everything operates as expected.

Please help me debug how to get the stored proc to return the same value every time the SSIS Package is run. thanks!

Here is the sequence of events and what happens....

  1. Look for a Positor that matches the Application, Host, and User
  2. No matching PositorId is found, Creates new Positor row, returns that new PositorId
  3. Use PositorId to upload some data (Every thing works)
  4. re-run/debug the ssis pacakge
  5. Look for a Positor that matches the Application, Host, and User 
  6. <No clue what is happening>
  7. Returns -1 (SHOULD BE the same PositorId value returned in #2)

"Execute SQL Task" Setup: No edits to Result Set nor Expressions

"Execute SQL Task" Setup: GENERAL

"Execute SQL Task" Setup: PARAMETER MAPPING

SP called by "Execute SQL Task"

CREATE PROCEDURE [posit].[Return_PositorId]
AS
BEGIN

	DECLARE @PositorId	INT = [posit].[Get_PositorId]();

	IF (@PositorId IS NULL)
	BEGIN

		DECLARE @ProcedureDesc	NVARCHAR(257) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
		DECLARE @PositorNote	NVARCHAR(348) = N'Automatically created by: ' + @ProcedureDesc;

		EXECUTE @PositorId = [posit].[Insert_Positor] @PositorNote;

	END;

	RETURN @PositorId;

END;

Supporting SQL Objects:

CREATE FUNCTION [posit].[Get_PositorId]
(
)
RETURNS INT
AS
BEGIN

	DECLARE @PositorId	INT = NULL;

	SELECT TOP 1
		@PositorId = [p].[PO_PositorId]
	FROM [posit].[PO_Positor] [p]
	WHERE	[p].[PO_PositorApp]		= APP_NAME()
		AND	[p].[PO_PositorHost]	= HOST_NAME()
		AND	[p].[PO_PositorUID]		= SUSER_ID();

	RETURN @PositorId;

END;
GO

CREATE PROCEDURE [posit].[Insert_Positor]
(
	@PositorNote	NVARCHAR(348) = NULL
)
AS
BEGIN

	DECLARE @ProcedureDesc	NVARCHAR(257) = OBJECT_SCHEMA_NAME(@@PROCID) + N'.' + OBJECT_NAME(@@PROCID);
	SET @PositorNote = COALESCE(@PositorNote, N'Automatically created by: ' + @ProcedureDesc);

	DECLARE @Id TABLE
	(
		[Id]	INT		NOT	NULL
	);

	INSERT INTO [posit].[PO_Positor]([PO_PositorNote])
	OUTPUT [INSERTED].[PO_PositorId]
	INTO @Id([Id])
	VALUES(@PositorNote);

	RETURN (SELECT TOP 1 [Id] FROM @Id);

END;
GO

CREATE TABLE [posit].[PO_Positor]
(
	[PO_PositorId]			INT					NOT	NULL	IDENTITY(0, 1),

	[PO_PositorApp]			NVARCHAR(128)		NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_PositorApp]	DEFAULT(APP_NAME()),
															CONSTRAINT [CL__PO_Positor_PO_PositorApp]	CHECK([PO_PositorApp] <> ''),
	[PO_PositorName]		NVARCHAR(256)		NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_PositorName]	DEFAULT(SUSER_SNAME()),
															CONSTRAINT [CL__PO_Positor_PO_PositorName]	CHECK([PO_PositorName] <> ''),
	[PO_PositorHost]		NVARCHAR(128)		NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_PositorHost]	DEFAULT(HOST_NAME()),
															CONSTRAINT [CL__PO_Positor_PO_PositorHost]	CHECK([PO_PositorHost] <> ''),

	[PO_PositorSID]			VARBINARY(85)		NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_PositorSID]	DEFAULT(SUSER_SID()),
	[PO_PositorUID]			INT					NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_PositorUID]	DEFAULT(SUSER_ID()),

	[PO_PositorNote]		VARCHAR(348)			NULL	CONSTRAINT [CL__PO_Positor_PO_PositorNote]	CHECK([PO_PositorNote] <> ''),

	[PO_tsInserted]			DATETIMEOFFSET(7)	NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_tsInserted]	DEFAULT(SYSDATETIMEOFFSET()),

	[PO_RowGuid]			UNIQUEIDENTIFIER	NOT	NULL	CONSTRAINT [DF__PO_Positor_PO_RowGuid]		DEFAULT(NEWSEQUENTIALID())	ROWGUIDCOL,
															CONSTRAINT [UX__PO_Positor_PO_RowGuid]		UNIQUE NONCLUSTERED([PO_RowGuid]),

	CONSTRAINT [UK__Positor]	UNIQUE CLUSTERED ([PO_PositorApp] ASC, [PO_PositorHost] ASC, [PO_PositorUID] ASC),
	CONSTRAINT [PK__Positor]	PRIMARY KEY ([PO_PositorId] ASC)
);
GO

ssd


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>