SQL Server query with Superset not allowing to execute stored procedure - sql-server

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

Related

Using stored procedure in openrowset throws login_mapping error

Because I need to fill a view with dynamic data, I wrote a stored procedure to collect the data and use select from OPENROWSET('SQLNCLI','server=....;trusted_connection=yes','EXEC Stored_Procedure') as the view definition.
As far as I know you can't use variables in your view definition so that's why I choose this route.
The stored procedure collects data from a linked server source combined with native SQL Server data. The linked_server has the appropriate permissions setup for the remote user and can be successfully queried from outside SQL Server.
That works very well in a local context but when I try to use the view in a PostGreSQL foreign-table I get an ODBC error. The first errors involved the permission to execute the stored procedure by the caller's user account. After that I get stuck. It seems the connection with the server has sufficient access permissions but the OPENROWSET call to execute the stored procedure does not (no login_mapping exists).
However, if I change the SQL in the OPENROWSET command to a simple select statement (select * from db.schema.table) it works fine.
I tried to change the server in de OPENROWSET to a datasource to the local server itself, with the remote user to impersonate, but with no luck either. The same login_mapping error.
My guess is that this has something to do with the fact that the users security context is not the one used by the OPENROWSET command?
I have looked around a lot but was not able to find a solution. Can you help me?

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

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

Can Execute Procedure But Job That Runs Procedure Errors?

I have a procedure that pulls data from my database and uses MSDB.DBO.sp_send_dbmail to send out e-mails. The procedure itself runs without a hitch when I use 'EXEC myprocedure'. But when I set up a job for the procedure, the job fails with the following error
'Error formating query, probably invalid parameters [SQLState
42000](Error 22050). The step failed'
There is one step in the job with the TSQL statement 'EXEC myprocedure', using the database that my procedure is stored on. Does anyone know what could be causing this error?
Update
I've narrowed the problem down. It's something with the Exchange server I use. I was using a domain address (ie. mail.mycompany.com) as the 'Server name' under Database Mail's account configuration wizard. I was unable to send e-mails to listservs and external users using this domain address. I talked to our Exchange guy and he recommended using the actual IP address of one of the mail servers (ie. 10.123.53.53). That fixed the problem with listservs and external users, but now I am unable to send e-mails when I run my procedure using a job (the procedure itself executes properly when I manually run it). Does anyone know what criteria on our Exchange server I will need to change to fix this?
This is like to be a permissions issue. It is impossible from the information given to specify exactly what permission is the problem, but a TSQL job step will run under the context of the Server Agent Service Account, so ensure that that account has SELECT permissions to the tables that are being used to build the query, and then make sure that it has permissions to the profile that you are using within Database Mail.
The problem was with the #query parameter used by sp_send_dbmail. For some reason, my SQL Server Agent account (which was a domain administrator) was denied access to use sp_send_dbmail with the #query parameter. I ended up dropping the #query parameter altogether and putting everything in the #body parameter. The #body parameter became a concatenation of regular text and what returned from a SELECT query.

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