Problem using parameters in a stored procedures when querying against a AS400 Linked Server

I have the following stored procedure,

CREATE PROCEDURE [dbo].[SelectAccidentContacts]

@Param bigint

AS

SELECT FieldA,  FieldB, FieldC
FROM LINKEDSERVER.AS400.AS400LIBRARY.FILENAME
WHERE (FieldA= @Param)

GO

When I execute this passing the @Param as a paramater it generates the following error.

OLE DB provider 'MSDASQL' reported an error. The provider reported an unexpected catastrophic failure.
OLE DB error trace [OLE/DB Provider 'MSDASQL' ICommandText::Execute returned 0x8000ffff:  The provider reported an unexpected catastrophic failure.].

If I change @Param to a fixed value it works OK (IE - WHERE (FieldA= 1234567).

I can set the fixed value as a string by encapsulating it in ' ' or just as a number and both work but no matter what datatype I use for the parameter it still returns the same error.

The DataType on the As400 is numerical with a length of 7 with no decimals.

I am currently trying to prove a concept for a new project and if I can't get this to work then my concept goes out the window so any help to resolve this would be greatly appreciated!
RayDalyAsked:
Who is Participating?
 
DarthModConnect With a Mentor Commented:
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0
 
kenpemCommented:
silly, silly question: is there a type in your example? Your procedure declares @Param as a parameter, but you try to validation against the non-existent variable @AccNo. Either change @Param to @Accno or vice versa. I'll be very surprised if SQL even accepts the procedure with an error like this in!
0
 
RayDalyAuthor Commented:
Sorry, that was me changing the paramater names & field names for this example, the paramater names are correct in my sp!!
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
imran_fastCommented:
change your procedure to be

CREATE PROCEDURE [dbo].[SelectAccidentContacts]

@Param bigint

AS

SELECT FieldA,  FieldB, FieldC
FROM openquery (LINKEDSERVER, 'select * from AS400.AS400LIBRARY.FILENAME')

WHERE (FieldA= @Param)

GO
0
 
RayDalyAuthor Commented:
OK Thanks, getting somewhere now. This does work but the OPENQUERY statement only selects a limited number of records from the AS400 table to query against, 107 to be precise, and there a 1000's in there.


 
0
 
imran_fastCommented:
RUN THIS QUERY TO CHECK HOW MANY RECORDS YOU HAVE IN YOUR TABLE
===================================================
Are you aware that the above mentioned post you are filtering the rows by mentioning the criteria of WHERE (FieldA= @Param)


SELECT count(*)
FROM openquery (LINKEDSERVER, 'select * from AS400.AS400LIBRARY.FILENAME')

and

SELECT *
FROM openquery (LINKEDSERVER, 'select count(*) from AS400.AS400LIBRARY.FILENAME')
0
 
RayDalyAuthor Commented:
Thanks but already did run this query to determine the number of rows, came back with 107. I seem to remeber when I was looking for the answer to my original problem that there is a restricted number of bytes that gets returned from a linked server by default and there's some way to increase it. Trying to hunt it down now.
0
 
imran_fastCommented:
ok
0
 
RayDalyAuthor Commented:
Still no Joy, gonna give up for today. Thanks for you help imram, atleast I've got the params working!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.