How to execute MariaDB stored procedure from azure data factory? - azure-cosmosdb

I wanted to 'Call' MariaDB Procedure from Azure Data Factory.
How can this be achieved, are there any other service which can be integrated with ADF to call this MariaDB procedures
I tried calling the procedure by writing the query using lookup activity.
It fails while showing this error.
ErrorCode=InvalidParameter,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The value of the property 'columns' is invalid: 'Value cannot be null.
Parameter name: columns'.,Source=,''Type=System.ArgumentNullException,Message=Value cannot be null.
Parameter name: columns,Source=Microsoft.DataTransfer.Common,'

Lookup activity reads and returns the content of the query. I tried to repro this by creating three stored procedures in Azure SQL database for Maria DB.
First Stored procedure is written to update the data in the table.
DELIMITER $$
CREATE PROCEDURE update_inventory()
BEGIN
UPDATE inventory SET quantity = 150
WHERE id = 1;
END$$
DELIMITER ;
When this procedure is called in ADF lookup activity, error occurs.
Second stored procedure is written with select query.
DELIMITER $$
CREATE PROCEDURE select_inventory()
BEGIN
select * from inventory;
END$$
DELIMITER ;
When this SP is called, ADF pipeline is executed successfully.
In order to execute the stored procedure with update statements (or any statements), a select statement is added in the Stored procedure.
DELIMITER $$
CREATE PROCEDURE update_select_inventory()
BEGIN
UPDATE inventory SET quantity = 150
WHERE id = 1;
select * from inventory;
END$$
DELIMITER ;
When this stored procedure is called through Lookup activity, it got executed successfully.
Try adding select statement in the stored procedure and execute it in Lookup activity. Or add Select statement after Call stored procedure statement.

By selecting the 'query' option, you can call the stored procedure using lookup activity. From your error message, it looks like you are missing the parameter columns while calling the stored procedure.
Did you try executing the same code using the client tools like MySQL workbench? If you can execute the stored proc from other client tools, then you should be able to execute the same using the lookup activity.
I tested from my end and was able to execute the Stored procedure using lookup activity. Please see the below screenshot for your reference.

Related

Tableau connecting to Teradata procedure with out parameters not showing

I need to save a few parameters into Teradata via Tableau, I created a Teradata procedure to do insertion but when I connect to the procedure in Tableau it kept on giving me error "xxxx stored procedure returned no result. bla bla".
In order to make stored procedure returns some result, I update the Teradata procedure to include a OUT parameter to return a dummy message, but in the list of Stored Procedures under Tableau connection, all procedures with OUT parameter are not showing.
Appreciate if anybody can help.
Tableau does not support procedure OUT parameters. You need the procedure to return a result set, e.g.
REPLACE PROCEDURE myProc(someInput INTEGER,...)
...
DYNAMIC RESULT SETS 1
...
BEGIN
DECLARE csr CURSOR WITH RETURN FOR SELECT 'OK';
...
OPEN csr;
END;

SQL Server always encrypted with Dynamic SQL

I am using SQL Server always encrypted on feature for SSN column. I have created a stored procedure and calling it from .net code. I am using column encryption setting=true in my connection string. Calling the dynamic stored procedure from the .net code throws this error:
Operand type clash: varchar is incompatible with varchar(4) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'ColumnKey', column_encryption_key_database_name = 'DatabaseName') collation_name = 'SQL_Latin1_General_CP1_CI_AS'
Could someone please provide a sample code which would work to retrieve data with the search on encrypted column using parameterization?
CREATE PROCEDURE [dbo].[testSSN_Dynamic]
#Last4SSN VARCHAR(50)
AS
BEGIN
DECLARE #query NVARCHAR(4000);
SET #query = 'Select [SSNumber], [last4SSNumber] from table_XXX WHERE last4SSNumber = #Last4SSN ;'
EXEC sp_executesql #query, N'#Last4SSN varchar(4)', #Last4SSN ;
END
In the application SSN number is encrypted using Randomized encryption. Last4SSNumber is encrypted using Deterministic encryption. The search is based on last 4 digit of SSN number and the filtered list will get the SSN number only with the last 4 matching digit, rest all the digits are masked in the application. Since both the encryption Randomized and deterministic do not support like operation the column last4SSNumber was added.
When I call the above Stored procedure without the dynamic SQL from .NET code, it works fine and I am able to retrieve the list of matching last 4 digit of SSN..
In the application there are existing stored procedure with quite a few parameters passed to them. The search criteria is based on if the value is passed to the parameter or not. Last4SSNumber is one of the parameter passed. I have provided a simple sample of the stored procedure and not the entire stored procedure with all of the parameters. The search criteria is build, depending on the value passed to the parameter.
In various post it has been pointed out that the Dynamic SQL has to be converted to Parameterized query in order to use the always encrypted on feature. I applied parameterization to the above stored procedure still I receive the error when calling the stored procedure from the .NET code.
Use Dynamic SQL with parameters that evaluate against encrypted columns is currently not supported.
Unfortunately executing the query in the manner below is not supported by Always Encrypted
EXEC sp_executesql #query, N'#Last4SSN varchar(4)', #Last4SSN ;
However, if you are able to restructure your stored procedure in the following manner, you may have a working solution.
CREATE PROCEDURE [dbo].[testSSN]
#Last4SSN VARCHAR(50)
AS
BEGIN
Select [SSNumber], [last4SSNumber] from table_XXX WHERE last4SSNumber = #Last4SSN ;
END

To retrieve list of object from stored procedure SQL server through spring-jpa

I wrote a stored procedure ,
ALTER PROCEDURE [dbo].[getCustomerSearch]
-- Add the parameters for the stored procedure here
#clientNo varchar(50)
AS
BEGIN
-- Insert statements for procedure here
SELECT cs.* FROM [mm].[dbo].[CM_customerStatus] as cs WHERE cs.[ClientNo] like #clientNo;
END
I want to access that list of table records from spring JPA repository as List of object.Is there any way to do this task???
You can extend your JPA repository and use EntityManager to run a stored procedure in spring data jpa. Use createNamedStoredProcedureQuery to fire your stored procedure.
Query query = entityManager.createNamedStoredProcedureQuery("YOUR_PROCEDURE");
query.setParameter("arg", ARG);
query.getResultList();
Also check this question for more details.

Executing sequential stored procedures; works in query analyzer, doesn't in my .NET application

I have an audit record table that I am writing to. I am connecting to MyDb, which has a stored procedure called 'CreateAudit', which is a passthrough stored procedure to another database on the same machine called MyOther DB with a stored procedure called 'CreatedAudit' as well.
In other words in MyDB I have CreateAudit, which does the following EXEC dbo.MyOtherDB.CreateAudit.
I call the MyDb CreateAudit stored procedure from my application, using subsonic as the DAL. The first time I call it, I call it with the following (pseudocode):
int openStatus, closeStatus = 0;
openStatus = Convert.ToInt32(SPs.LogAccess(userId, "OPENED"));
closeStatus = Convert.ToInt32(SPs.LogAccess(userId, "CLOSED"));
This is simplified, but this is what LogAccess calls:
ALTER procedure [dbo].[LogAccess]
#UserID uniqueid,
#Action varchar(10),
#Status integer output
as
DECLARE #mStatus INT
EXEC [MyOtherDb].[dbo].[LogAccess]
#UserID = #UserID,
#Action = #Action,
#Status = #mStatus OUTPUT
select #mStatus
In my second stored procedure it is supposed to mark the record that was created by the CreateAudit(recordId, "Opened") with a status of closed.
This works great if I run them independently of one another, or even if I paste them into query analyzer. However when they execute from the application, the record is not marked as "Closed".
When I run SQL profiler I see that both queries ran, and if I copy the queries out and run them from query analyzer the record gets marked as closed 100% of the time!
When I run it from the application, about once every 20 times or so, the record is successfully marked closed - the other 19 times nothing happens, but I do not get an error!
Is it possible for the .NET app to skip over the ouput from the first stored procedure and start executing the second stored procedure before the record in the first is created?
When I add a "WAITFOR DELAY '00:00:00:003'" to the top of my stored procedure, the record is also closed 100% of the time.
My head is spinning, any ideas why this is happening!
Thanks for any responses, very interested in hearing how this can happen.
In your 1st stored proc, try having the EXEC statement wait for a return value from the 2nd stored proc. My suspicion is that your first SP is firing off the 2nd stored proc and then immediately returning control to your .NET code, which is leading to the above commenter's concurrency issue. (That is to say, the 2nd SP hasn't finished running yet by the time your next DB call is made!)
SP1: EXEC #retval = SP2 ....

Easiest method to test an Oracle Stored Procedure

I'm working on an ASP.NET project with an Oracle Database. We are using TOAD to add/manage the stored procedures -- and in general I like TOAD and Oracle. The one thing I've found frustrating is finding a simple way to test an Oracle Stored Proc, such as SQL Server's "exec [SP_NAME] Param1, Param2, ParamN" syntax.
All of our stored procedures output Ref Cursors. Here is an example of a Stored Proc:
CREATE OR REPLACE PROCEDURE APP_DB1.GET_JOB
(
p_JOB_ID IN JOB.JOB_ID%type,
outCursor OUT MYGEN.sqlcur
)
IS
BEGIN
OPEN outCursor FOR
SELECT *
FROM JOB
WHERE JOB_ID = p_JOB_ID;
END GET_JOB;
/
Any suggestions?
You just need a script that calls your stored procedure and has a bind variable for the ref cursor output to display it in TOAD's grid in the Editor window.
DECLARE
type result_set is ref cursor;
BEGIN
APP_DB1.GET_JOB(1, :result_set);
END;
When you then run this TOAD will prompt you to 'bind' :result_set, just select ref cursor from the list of types and then the result will display in the grid. The trick is to think of yourself as a 'client' calling your stored procedure and you need your own ref cursor to store the result.
If you just looking for a way to invoke the SP, then the Oracle way is:
begin
sp_name(....);
end;
I don't use Toad, but you should be able to put this into a SQL window and execute it.
In sqplus you can use the syntax
SQL>var rc refcursor
SQL>exec APP_DB1.GET_JOB(the job id you want to query, :rc)
SQL>print rc
That should do it. The first line defines a bind variable. You could also define a variable for the job id, or just type it in.
TOAD shows the result in a grid just fine with sample script from Russel. Run as script.
variable P_CUR refcursor;
exec PACK.GETEXECUTION ( '9f363e49-88c1-4295-b61e-60812d620d7e', '6', :P_CUR );
print P_CUR;
Thanks!
The idea is just to bind the outCursor variable to a cursor when toad prompts you for the variable type. Just pass the other variables the usual way. Like in the example below.
BEGIN
APP_DB1.GET_JOB(1, :v_outCursor);
END;
Run it and a dialogue box will prompt you to bind the :outCursor variable as shown in the following image.
Toad will then display the result in the result grid.

Resources