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

Error converting data type varchar to varbinary

$
0
0

We are performing a SELECT for Change Control and a [LSN] data column, Log Sequence Number. We are storing [LSN] as a local variable as a String data type. We are then using a Data Flow Task and an OLE DB Source to EXEC our SQL Server Stored Procedure.

The [LSN] Input parameters, both @MinLSN and @MaxLSN, are defined as VARCHAR(MAX) within the SQL Server Stored Procedure. And we are then converting them in the SQL Server Stored Procedure by...

CREATE PROCEDURE [Schema].[SPROCName]
    @MinLSN_In VARCHAR(MAX) NULL,
    @MaxLSN_In VARCHAR(MAX) NULL
--WITH EXECUTE AS CALLER, RECOMPILE
AS
SET NOCOUNT ON;

--Create @MinLSN_LOCAL and @MaxLSN_LOCAL Variables To Local Variables to Prevent Parameter Sniffing!!
--Reference: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b818092b-9439-48cd-9f01-cf5e798c2fcb/error-converting-nvarchar512-to-varbinarymax?forum=sqlintegrationservices
DECLARE @MinLSN_BINARY  VARBINARY(MAX),
        @MinLSN_LOCAL   VARCHAR(MAX),
        @MaxLSN_BINARY  VARBINARY(MAX),
        @MaxLSN_LOCAL   VARCHAR(MAX),
        @OrderInvoiceID INT;

--SET Local Variables to prevent Parameter Sniffing!
SET @MinLSN_LOCAL = @MinLSN_In;
SET @MaxLSN_LOCAL = @MaxLSN_In;

--The @MinLSN_In and @MaxLSN_In Parameters will come from the SSIS Package and the derivation
--of each based on the Change Control LSN. SSIS forces you to store the LSN as a String
--so that is what is actually passed to this SQL Server Stored Procedure and the LSN will
--need to be converted back to BINARY in order to perform the Change Control LSN lookups.
SELECT @MinLSN_BINARY = CONVERT(VARBINARY(MAX), @MinLSN_LOCAL, 1);
SELECT @MaxLSN_BINARY = CONVERT(VARBINARY(MAX), @MaxLSN_LOCAL, 1);

NOTE THE REFERENCE TO...

 https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b818092b-9439-48cd-9f01-cf5e798c2fcb/error-converting-nvarchar512-to-varbinarymax?forum=sqlintegrationservices

I tried all of that and am still getting the error:

An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80040E07  Description: "Error converting data type varchar to varbinary.".
Error: 0xC004701A at Data Flow Task, SSIS.Pipeline: OLE DB Source failed the pre-execute phase and returned error code 0x80040E07.

Can anyone shed any light on this? Please!

Thanks for your review and am hopeful for a reply.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



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