I have a stored procedure which I like to use with LINQ to SQL. I got it added to dbml just fine and manage to call it but then the weird stuff happens. I'm getting the "Cannot find either column "MySchema" or the user-defined function or aggregate "MySchema.pi_MyStoredProcedure", or the name is ambiguous." -error. Tried to figure out why this is happening since I can execute the proc just fine from SSMS. SQL Profiler managed to catch the query and it was like this:
exec sp_executesql N'SELECT CONVERT(Int,[MySchema].[pi_MyStoredProcedure](#p0)) AS [value]',N'#p0 nvarchar(4000)',#p0=N'ParameterValue'
I get the same "cannot find..." -error from SSMS when I try to execute this. I suspect this may have something to do with the return type of my stored proc. I had to set it by hand in the .dbml XML code. That looks like this:
<Function Name="MySchema.pi_MyStoredProcedure" Method="pi_MyStoredProcedure" IsComposable="true">
<Parameter Name="MyParameter" Type="System.String" DbType="NVarChar(512)" />
<Return Type="System.Int32" />
</Function>
What am I doing wrong here? Every online tutorial I've managed to find tell me to do this but obviously there's something else I'm missing? What is it?
I managed to fix this by changing the Stored Procedure to use OUTPUT parameter instead of RETURN.
Related
UPDATE 11.15.2022
I have conducted extensive testing and found the pattern of problem here. Once again, what's strange is this ONLY happens if you pass a function as a parameter to the originating Stored Procedure; passing a hardcoded value or variable works just fine.
The issue is when the Stored Procedure calls another Stored Procedure that checks ##read_only to see if it can WRITE to the database. I confirmed removing any code that writes data fixes the issue -- so ultimately it appears passing a STATIC value to the SP causes the procedure execution to bypass any writing (as expected) because of the IF ##read_only = FALSE THEN ...write...
It seems passing a function somehow causes MySQL to compile a "tree" of calls and subcalls to see if they CAN write rather than if they DO write.
It appears the only way to work around this is to pass the parameters as variables rather than function calls. We can do this, but it will require substantial refactoring.
I just wonder why MySQL is doing this - why passing a function is causing the system to look ahead and see IF it COULD write rather than if it does.
We have a Read Replica that's up and running just fine. We can execute reads against it without a problem.
We can do this:
CALL get_table_data(1, 1, "SELECT * from PERSON where ID=1;", #out_result, #out_result_value);
And it executes fine. Note it's READS SQL DATA tagged. It does not write anything out.
We can also do this:
SELECT get_value("OBJECT_BASE", "NAME");
Which is SELECT function that is READ ONLY.
However, if we try to execute this:
CALL get_table_data(1, get_value("OBJECT_BASE", "NAME"), "SELECT * from PERSON where ID=1;", #out_result, #out_result_value);
We get the error:
Error: ER_OPTION_PREVENTS_STATEMENT: The MySQL server is running with the --read-only option so it cannot execute this statement
We're baffled at what could cause this. Both the SP and function are read-only and execute individually just fine, but the second we embed the function result in the call of the SP, the system chokes.
Any ideas?
So AWS cannot figure this out. The issue only happens when a function is passed as a parameter to a stored procedure that calls another stored procedure (not even passing the value of the function) that has a ##read_only check before doing an INSERT or UPDATE. So for some reason, the system is doing a pre-scan check when a function is passed vs. a variable or hardcoded value.
The workaround is to pass the function value as a variable.
I'm going to report this issue to Oracle as it might be some sort of bug, especially given the function is DETERMINISTIC.
I read up most of the websites with examples and the mybatis documentation. I am definitely missing something simple and am going to look really stupid.
Can someone please take a look at why this procedure does not even get called when my DAO invokes the id?
Here is what I added to my .xml file.
<parameterMap id="validateProcedure_paramMap" class="java.lang.Long">
<parameter property="requestId" jdbcType="NUMERIC" mode="IN">
</parameterMap>
<!-- Calls stored procedure -->
<procedure id="validateRequest" parameterMap="validateProcedure_paramMap">
{call NG_PKG.validateRequest_sp(?)}
</procedure>
I just call it normally via the DAO. The DAO is getting the long parameter passed in
public void validateRequest(long reqId) throws SQLException
{
sqlMap.queryForObject("validateRequest", reqId);
}
Can someone see if I am doing anything wrong - and what is it that I am doing wrong :(
Control just goes over the DAObut does the procedure is not getting called in the database.
Sorry, Folks I should have posted what I found out.
I was looking in the wrong place. My procedure seems to have been getting called. It is just that my transaction handling that was being done was not committing this part of it.
I had a separate method that has a starttransaction and a commit transaction and an endtransaction using the ibatis SQLTransactionManager.
The method that calls this stored procedure gets called after that. For some reason, it wouldn't commit this. I removed the endtransaction on the different method and am only ending it in one palce - which is actually what I want. I only want to commit at the end of the validation procedure anyways. So, it works after I played around with my transactionmanagement.
I'm trying to call a stored procedure that takes one parameter on Mysql from ssrs. Connecting through ODBC. I use following syntax for calling using query designer:
`CALL test.ClientSelectExtract(?)`
And I'm getting following error.
`SQLBindParameter not used for all parameters`
I found the solution. Read from an article that MySql ODBC don't support named parameters.
So I called the stored proc like this
CALL test.ClientSelectExtract(?)
Added a parameter named parameter1 in the Parameters Folders then set the type and value, then explicitly created a parameter named parameter1 to reference the ? on the dataset also, then all worked fine.
Note: If I had more ? placeholders the next param would be parameter2, same steps and so on.
You should create linked server in SSMS from MYSQL then only we will call the stored procedure. syntax to call stored procedure:
EXEC ('CALL GASP_sales_aps(?, ?)', #dt_start, #dt_end)AT MySQL(Linked Server Name)
GASP_sales_aps ---->procedure Name
(#dt_start,#dt_end)------> are parameters .
I am using the RODBC package to query for results in my SQL server. I have a certain stored procedure written that, when executed in my SQL Server Mgmt. studio (for example), returns a table. However, when I run the query through R, it returns character(0)
# Execute command...
sqlQuery(production,"exec port.tdp_RISK2_ModelRunCompare #ModelRunId1 = 399")
Weird thing is... when I do something like...
sqlQuery(production,"exec sp_who")
I get a table of results...
Help?
I had the same problem.
You can try using:
set nocount on
in the MS SQL Server stored procedure so it will return just a dataset.
Regards,
Try this:
sqlQuery(production,"exec port.tdp_RISK2_ModelRunCompare #ModelRunId1 = 399", errors=FALSE)
Also try writing to a new data frame. I kept getting character(0) when I tried to overwrite an existing data frame with the sqlQuery function.
I'm using Linq-to-SQL query and using stored procedure in that. I'm getting error :
Specified cast is not valid.
How to solve it ?
Check your TDetail.AMOUNT values.
Your error is not when casting to an array, but rather in the Convert.ToDouble(TDetail.AMOUNT).
Run your stored proc with those same arguments (in SSMS or Visual Studio), and try to determine which value in TDetail.AMOUNT is causing this problem.
You're seeing this exception being thrown when you cast to an array, but it would happen whenever you evaluated your LINQ query. It's nothing to do with ToArray(). It could be ToList(), and you'd find the same exception.