Solved

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

Posted on 2006-06-25
10
366 Views
Last Modified: 2008-01-09
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!
0
Comment
Question by:RayDaly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 4

Expert Comment

by:kenpem
ID: 16978343
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
 

Author Comment

by:RayDaly
ID: 16978347
Sorry, that was me changing the paramater names & field names for this example, the paramater names are correct in my sp!!
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 16978397
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RayDaly
ID: 16978439
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
 
LVL 28

Expert Comment

by:imran_fast
ID: 16978494
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
 

Author Comment

by:RayDaly
ID: 16978530
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
 
LVL 28

Expert Comment

by:imran_fast
ID: 16978555
ok
0
 

Author Comment

by:RayDaly
ID: 16978933
Still no Joy, gonna give up for today. Thanks for you help imram, atleast I've got the params working!
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17528334
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question