Solved

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

Posted on 2006-06-25
10
362 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
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

830 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