Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute stored proc with OPENQUERY

I have SQL Server 2008 with a linked Sybase server and I am trying to execute a stored procedure on the Sybase server using OPENQUERY. If I have a stored proc that doesn't take parameters it succeeds fine. If I have a stored proc with parameters it fails. I even tried a very basic stored proc that only took an int an that still failed. Below is the syntax I am using:

select * from 
OPENQUERY([LINKSERVER],'exec database.user.my_stored_proc ''AT'',''XXXX%'',''1111'',1')

Msg 7357, Level 16, State 2, Line 3 Cannot process the object "exec database.user.my_stored_proc 'AT','XXXX%','1111',1". The OLE DB provider "ASEOLEDB" for linked server "LINKSERVER" indicates that either the object has no columns or the current user does not have permissions on that object.

As the proc will execute just fine without parameters, I don't think it is a permission issue.

like image 213
ctrlalt313373 Avatar asked Nov 11 '10 21:11

ctrlalt313373


People also ask

Is Openquery faster than linked server?

The OPENQUERY is faster than the linked server because when we use the linked server, the SQL Server breaks the query into local and remote queries. The local queries are executed on the local server, and remote queries will be sent to the remote server.

How do I select a stored procedure in SQL?

Using SQL Server Management Studio Expand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To.


1 Answers

This worked for me,

SELECT * FROM OPENQUERY(LOCALSERVER, 'SET FMTONLY OFF EXEC snr.dbo.GetAllSignals @controlRunId = 25, @experimentRunId = 26')

I was creating temporary tables, and that's why i got access denied

Here is more info http://www.sommarskog.se/share_data.html#OPENQUERY

like image 151
mrwaim Avatar answered Oct 01 '22 19:10

mrwaim