sp_reset_connection error in SQL Azure Linked Server RPC - sql-server

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

Related

SQL Server query with Superset not allowing to execute stored procedure

I am trying to execute the following stored procedure in Superset SQL Editor:
Exec [CI_DW1].[Reports].[spGetPSBMFuelBidOfferVolume]
#fromDate = '20220824',
#toDate = '20220824'
But when I press 'Run Selection', it returns the following error:
DB engine Error
Only SELECT statements are allowed against this database.
I can confirm that the user does have exec permission on the database, and successfully tested it by running as the user in SQL Server Management Studio.
My connection string is:
mssql+pyodbc://username:password#server:port/database?TrustServerCertificate=YES&driver=ODBC+Driver+18+for+SQL+Server&encrypt=yes
And I can use the connection to run select queries in superset successfully.
Has anyone else come across this before? Is it a limitation of superset or is there a way to solve this?
It looks like superset does not allow you to call the stored proc, but there is a workaround you can use OpenQuery to get the result from a stored proc

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

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()'

SQL Server Linked Server, Error running query firebird

I'm doing a query on the firebird external database from SQL Server (2008, 2012). The server connects seamlessly to the linked server, but to consult the following error.
ADDITIONAL INFORMATION:
Object reference not set to an instance of an object. (Microsoft.SqlServer.ConnectionInfo)
===================================
You can not run the script.
===================================
Object reference not set to an instance of an object. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Program location:
on Microsoft.SqlServer.Management.Common.ConnectionManager.UpdateDatabaseEngineType()
on Microsoft.SqlServer.Management.Common.ConnectionManager.get_DatabaseEngineType()
on Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptAndResultsEditorControl.DebugWrapper.Start()
on Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptAndResultsEditorControl.OnDebugScript(Object sender, EventArgs a)
The query worked until a few days ago, but now I get this error.
Might be wrong?
this is the query:
SET #QUERYSTRING = 'SELECT #HAST=HASTA, #ABON=ABONOCONTRATO FROM OPENQUERY( CnxAdasysWS, ''SELECT first 1 HASTA, ABONOCONTRATO FROM TBLPAGOS WHERE TM=0 AND ANULADO=0 AND IDCONTRATO ='''''+#NOCONTRATO+''''' ORDER BY IDGENERADOR DESC'')';
EXECUTE SP_EXECUTESQL #QUERYSTRING, N'#HAST DATE OUTPUT, #ABON FLOAT OUTPUT', #HAST=#PAGOHASTAMOVIL OUTPUT, #ABON=#ABONOCONTRATO OUTPUT
I run the query in SQL management studio and came out the same mistake as I configured the linked server several times, but no error above shows create. Connection test shows no problems
It's not easy to identify the problem outside of your network. The think I've in mind is verify if the connections between the servers are OK, firewalls servers and security rules.
Try to make a simple select between the servers to be sure that the connections are working well.

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.

Execute an Oracle stored procedure from a SQL Server stored procedure

I have a SQL Server stored proc that needs to send information to an Oracle stored proc.
How do I set this up? Should it be a linked server? And how do I write the code to pass and execute the stored proc?
You could also use:
DECLARE #outputParameter int
EXEC ('BEGIN <procedureName>(?,?); END;', #inputParameter , #outputParameter OUTPUT) at <linkedServerName>
This allows capturing output parameters
a procedure "TestingProcedure" in Oracle server.
a linked Server "LinkedServer" in SQL Server.
call TestingProcedure in SQL server example:
EXECUTE ('begin TestingProcedure; end;') AT LinkedServer;
This is the syntax that I would probably try from the start:
SELECT * FROM OPENQUERY(<linked server name>, '{CALL <oracle sp>}')
What I've seen (I have not tried this myself) is that you can also use OPENQUERY to call an Oracle function which can then call the stored procedure, or you can turn the stored procedure into a function. Your connection from SQL Server would then look something like this:
SELECT * FROM OPENQUERY(<linked server name>, 'SELECT <oracle function> FROM dual')
Turns out I ended up having to use Microsofts CLR and write my own little C# application in order to handle the variables being pushed between the servers. Here's what I did:
C# Application starts on a scheduled task in windows
Application executes the SQL Server stored procedure and gets the return values
Application then executes the Oracle stored procedure with appropriate values

Resources