OLE DB provider "OraOLEDB.Oracle" for linked server returned message "ORA-06576: not a valid function or procedure name" - sql-server

I have setup a linked server from SQL Server to a Oracle database. Connection has been tested as successfully. I use the following to query a table from SQL Server and it successfully returned me the result set:
EXEC ('select * from tablename') AT [linkedservername]
I ran the following from the Oracle database, it(stored procedure) works:
EXEC schemaname.storedprocedurename
However, when I ran this from SQL server, it returned me the error message ORA-00900: invalid SQL statement
EXEC('call schemaname.storedprocedurename') AT [linkedservername]
Anyone has any idea what might be the cause?

Matt,
You are missing the () after the procedure name.
EXEC('call schemaname.storedprocedurename()') AT [linkedservername]
Also, make sure of the following
The account being used to link the servers has access to the stored procedure (schema)
Sometimes you may need to omit the schema name and just do the 'Call SPName()'

Related

execute Oracle stored procedure from SQL Server 2012

I have changed variable names to protect customer.
I am trying to execute a stored procedure from a remote Oracle 12c database, from my SQL Server 2012 database. If it helps, the Oracle database pl/SQL procedure is has input data types of: INPUT1=CHAR(200), INPUT2=(NUMBER), OUTPUT=SYS_REFCURSOR
I am constantly getting the following error:
"OLE DB provider "OraOLEDB.Oracle" for linked server "testsrv1" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.""
My query is found below:
DECLARE #outputParameter int
DECLARE #inputParameter varchar(400)
DECLARE #inputParameter1 varchar(400)
set #inputParameter1 = 'SampleStringValue'
set #inputparameter = SampleNumberValue
EXEC ('BEGIN storedProcedure(?,?); END;', #inputParameter, #inputParameter1, #outputParameter OUTPUT) at testsrv1
After many hours of research, I found that you cannot return a SYS_REF_CURSOR data type over a database link. Even from an Oracle database to another Oracle database.
https://asktom.oracle.com/pls/apex/asktom.search?tag=returning-result-set-from-stored-procedure-over-a-database-link
If Oracle database A is the DB producing the SYS_REF_CURSOR, and database B is the consumer - the only way that I have found online is to retrieve the data inside database A and store into a table, then pass the table via database link.
Is this really the only way to do this? I am somewhat new to oracle, but this seems like something that should be able to be done by now. The link from above is from 10+ years ago.
You can use SSIS and the SSIS Data Streaming Destination to connect to Oracle in SSIS and consume the output of the SSIS package in a SQL Query.
From SSIS you can use OleDB, ODBC, ADO.NET connectors for Oracle, or you can use a .NET script to connect to Oracle.

sp_reset_connection error in SQL Azure Linked Server RPC

I have a problem calling a remote Stored Procedure (RPC) on my SQL Azure, passing through a Linked Server (build on a Sql Server 2008 R2 instance: 10.50.2550.0 - x64 - Enterprise Edition).
This issue is not difficult to reproduce, and it's not really related with "calling" the Stored Procedure, but with its internal execution (I think)...
Take a look to my simple code:
CREATE PROCEDURE [dbo].[myStoredProcedure]
#AccountId INT = NULL
AS
BEGIN
DELETE FROM [dbo].[myTable];
INSERT INTO [dbo].[myTable] (Col1, Col2)
SELECT DISTINCT
Value1
, Value2
FROM [dbo].[myTableSource];
END
GO
GRANT EXECUTE ON [dbo].[myStoredProcedure] TO [myDbRole]
GO
When I launch this through my Linked Server, using this code (on a connection from my local instance, where the Linked Server has been created)...
EXEC('[AZURE_LINKEDSERVER].[myDatabase].[dbo].[myStoredProcedure] #AccountId = NULL')
...I get this error (that seems a warning!):
Message 2812, level 16, state 62, row 1
Could not find stored procedure 'sp_reset_connection'.
And obviously I checked everywhere and I'm not calling that Stored Procedure...that I think it's internally used by Sql Server.
I also tried this code, same result:
EXEC sp_sqlexec '[AZURE_LINKEDSERVER].[myDatabase].[dbo].[myStoredProcedure] NULL'
The Linked Server has "remote RPC enabled" (rpc and rpc out options are both set to True) and works great with other Stored Procedure and every other OPENQUERY code I used until now: also permissions work fine.
The strange thing is that the first part of the SP is correctly executed (I see query result count in the Messages window of SSMS), but the second is not called at all.
Can you please tell what's the SP sp_reset_connection is related to?
Do you know a workaround to call my SP without errors?
I tried everything...
SQL Azure in use has version 11.0.9231
sp_reset_connection is not an actual stored procedure it is a flag in the TDS stream that says "Reset the connection" so you can use connection pooling. It should exist on all SQL Servers implicitly but cannot be called by your code.
what type of linked server have you setup? follow this to create a linked server to azure:
http://blogs.msdn.com/b/sqlcat/archive/2011/03/08/linked-servers-to-sql-azure.aspx

Unable to call stored procedure from linked server

I am facing a strange issue. I have a linked server on ServerB for ServerA
Now, when I am calling a stored procedure from ServerB like
EXEC [ServerA].[Db].[dbo].[SpName] #Param1 #param2
I am getting error that
The EXECUTE permission was denied on the object 'SpName', database 'Db', schema 'dbo'.
But now when I am executing below query it is returning me result:
SELECT *
FROM [ServerA].[Db].[dbo].[tblName]
I don't know that why I am not able to execute stored procedure from ServerB. I am Db_Owner on both the server.
Screenshot of Linked server security
Linked server catalog
If a linked server query fails, the things to check are (in rough order of probability):
Try logging in locally on the linked server to test access directly. If you have no local access, obviously you won't have it through the link either.
Verify the correct credentials as used when accessing the linked server, and not another user you're not expecting. You can check this with EXEC ('SELECT USER_NAME(), SUSER_NAME()') AT [Server]; if the user name is not what you're expecting, check your linked server definition for the correct login mappings. If you can't access the server at all (any query fails), you have other problems (like Kerberos authentication issues if you're using integrated authentication).
Perform a sanity check that you're accessing the correct server with EXEC ('SELECT ##SERVERNAME') AT [Server]. The network name of a linked server can be changed using sp_setnetname, so the name you use to a access the server isn't necessarily the machine name.
If all else fails, dropping and recreating the linked server definition is always an option, but obviously this could disrupt production work.

SQL server - job calling procedure and procedure difference

I'm trying to create table from view from remote server (calling procedure UPDATE_PROC), like this:
SELECT *
INTO table
FROM [remote_server\database].DATABASE.dbo.view
And it works perfectly.
Problem is, when I try to create a new job, which is calling the previously worked stored procedure UPDATE_PROC
exec UPDATE_PROC
It doesn't work and reports:
Executed as user: NT AUTHORITY\SYSTEM. The OLE DB provider "SQLNCLI10" for linked server "remote_server\database" does not contain the table ""DATABASE"."dbo"."view"". The table either does not exist or the current user does not have permissions on that table. [SQLSTATE 42000] (Error 7314). The step failed
So it seems to be same, but it isn't. What I'm doing wrong?
UPDATE:
Remote server is SQL Server 2005, job is on SQL Server 2008
I'm logged as sa user. Procedure is working always, job calling stored procedure never
Job isn't run as sa user, but I don't know which user and where should be defined to execute the job propery....
It seems to me that's a security issue. User under which the job is running doesn't have permissions to access table on the remote server.

How to query remote index catalogs

I've been trying to create a linked server in SQL Server that accesses a
remote Index Service catalog, but I can't seem to do it. Let's call
the remote server "remoteServer" and the Catalog "remoteCatalog"
I've tried this:
EXEC sp_addlinkedserver remoteIndexServer, 'Index Server', 'MSIDXS',
'query://remoteServer/remoteCatalog'
and then i did run the SQL
SELECT * FROM OPENQUERY(remoteIndexServer,'select filename from scope()') AS Q
But i got the error as
OLE DB provider "MSIDXS" for linked server "remoteIndexServer" returned message "Service is not running. ".
Msg 7320, Level 16, State 2, Line 3
Cannot execute the query "select filename from scope()" against OLE DB provider "MSIDXS" for linked server "remoteIndexServer".
I have experienced this issue before. This is from memory so excuse any errors but if I recall correctly you will need to do the following.
Install the indexing service on your local SQL Server (this is so the provider is available).
Add a linked server to this LOCAL indexing service.
You can then run you query as below
SELECT *
FROM OPENQUERY(
LocalLinkedServer,
'select filename from RemoteServer.CatalogName..scope()'
) AS Q
If that doesn't work let me know, there is a post somewhere that describes how to do this. I can look it up if necessary but I think the above is right.

Resources