SSRS / MySQL / Stored Procedure with parameters through ODBC - mysql

We are using SQL Server 2012 and MySQL 6 and though I can write a SQL statement directly in the Dataset window, I cannot seem to get a MySQL Stored Procedure to work by passing parameters via CALL:
Actuaaly my problem is
either SSRS or the ODBC driver is having a problem sending/receiving the parameter value.
Other attempts at syntax:
call shop.GetRegions() ,
call shop.GetRegions(?) ,
call shop.GetRegions(regid) ,
call shop.GetRegions(#regid)
None of these worked.
If I call the procedure with a hard coded value i.e. call shop.GetRegions(5) - it works.
Again, if the stored procedure has no parameters it works fine.
Can anyone give me any real direction on this issue. A sample of the correct syntax or a step by step example would really be appreciated.

Finally I got solution struggled by couple of days.
We should create linked server in SSMS from MYSQL and then only we need to 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 .

If you don't want to use a linked server you can
set the dataset type to be Text
set the query to
="exec GASP_sales_aps'," & Parameters!#parameter1.Value & "','" & Parameters!#parameter1.Value &"'"

#RegBes is correct instead of linked server set the dataset type to Text. small workaround in syntax add the parenthesis and instead of exec need to use call for mysql.
="call GASP_sales_aps('," & Parameters!#parameter1.Value & "','" & Parameters!#parameter1.Value &"')"

Related

Use function call in passthrough query?

I have a passthrough query in an Access 2010 application, which I'm using to call a stored procedure on a SQL Server backend. The stored procedure takes a parameter that I need to make dynamic. The problem is this:
Execute spMyProc 'userName' works as expected.
Execute spMyProc getUserName() generates a "syntax error at ')'" message.
Is it possible to use a function as a parameter in a pass-through query?
Also, I should note that I'm migrating a complex Access application to SQL server, and I'm really not well-versed in what I'm doing. Any suggestions on things I'm doing incorrectly will be gratefully received. This particular question is rising from an attempt to change the Record Source of a Form from a simple select statement in the Record Source property to something that can be run on the server.
You can use this code:
With CurrentDb.QueryDefs("MyPass")
.SQL = "exec spMyProc '" & getUserName() & "'"
.Execute
End With
Because getUserName() is a local VBA function, then you need to pre-evaluate the actual string sent to SQL server. As above shows using a saved pass-though is "handy" since you don't have to deal with connection strings etc.

Invalid descriptor index on LAST_INSERT_ID after insert

Strange situation with my ODBC code ( called from a C library ). Basically, I have the following sequence of events:
Create insert statement ( just a string )
Call SQLPrepare with that insert statement string
Bind the various parameters ( column values ), using
SQLBindParameter
Call SQLExecute to insert the row ( this works, by the way, as I can
see the row in the MySQL DB )
Create "select last_insert_id()" statement string
NOTE: if in SQL Server mode, we would create a "select ##identity"
statement
Bind column using SQLBindCol - this is where I get the "Invalid
descriptor index" error
NOTE: if in SQL Server mode, this works fine, with no error
Call SQLExecDirect to get the last insert id - this never happens
because of SQLBindCol error
Does the standard MySQL ODBC connector require something special in this situation? Does anyone have an ODBC example of this type of "insert" then "get last insert id" behavior? Maybe I need to call "SQLPrepare" before step 6 ( where I bind the column )? Another way to ask this: Should there be an SQLPrepare call for each SQLExecute or SQLExecDirect call?
I know it works directly in SQL, so the problem is my C ODBC code.
Thanks.
For those who are interested, I ended up changing the above steps by adding an SQLPrepare call between creating the "select last_insert_id()" ( step 5 ) and calling SQLBindCol ( step 6 ). Not sure if that would work for others, but it seems to be working rather well for me.
As for research, I looked all over the place online and never found a really good or clear answer. Most comments were about the SQL involved, not ODBC. And the references to ODBC were vague and did not seem to apply to my situation, from what I could see.
My assumption is that the SqlServer ODBC driver I am using handles the missing prepare statement differently ( maybe even better, but that is debatable ) than my MySql ODBC driver.
SQL Server ODBC driver was the one provided by Easysoft
MySql ODBC driver was the one provided with the standard CentOS install of MySql
Hopefully this will help people. Obviously, if people have a better idea, please tell us.

VBScript using stored procedures not working when introducing new column

I'm working on a desktop-application, database, webserver-access combination which someone wrote some years ago. My task is to do some optimications/refactoring and to introduce new features to this application(s). I have not much experience in developing web applications, so it's quite difficult for me to find a solution to my problem described below, hoping someone can help me.
The webapplication is written with ASP and VBScript having some small javascript functions which do not affect my question. It uses ADODB for communicating with the database.
The database is a MS-SQLserver 2008 database.
The desktop-application is written in C++/CLI using the .Net built-in features for communicating with the database. With this application everything is working.
For introducing some features I need to add new columns to tables in the database. Inserting and updating of the main table is done with stored procedures. I added a column named "internal" of type "bit":
ALTER TABLE maintable
ADD internal bit
GO
I altered the stored procedures for inserting and updating, just by adding the internal column and a parameter for it. I made only these changes:
1x line for the parameter
added internal in the column and values list for the insert
added setting internal column with parameter for the update
In the vbscript which already was working before any changes I added the code for appending the value for internal as new parameter (its the same for insert & update):
sqlcmd.Parameters.Append(sqlcmd.CreateParameter("#internal",11,1))
sqlcmd.Parameters("#internal")=0
After these changes the update und insert procedures of the vbscript stopped working. I tried several datatypes for the parameter and also changing the column (different name, different datatype). Nothing worked. The stored procedures themself are working fine when executed directly in the database and also when used by the desktop-application.
I started to debug everything with printing some debuginformations ect. I added try/catch in the stored procedures and a outparameter to get some errors according to this answer and I selected all input-parameters into a varchar outparameter. This caused the next strange results.
While updating "worked" (because the stored procedure didn't cause a database error and I got the input-parameter informations which didn't show wrong values, but no update was performed) inserting didn't workin any way. My tracing outputs where printed till the sqlcmd.Execute, this line seems to crash since the trace outputs after this line wheren't printed. As long as I did not use the outparameter the insert itself didn't work, but all trace outputs got printed. I tried to retrieve information about a possible database error directly after the execution of the code with:
DECLARE #ErrorVariable INT;
SET #ErrorVariable = ##ERROR;
SELECT #ErrorVariable AS ErrorID,
text
FROM sys.messages
WHERE message_id = #ErrorVariable;
GO
There was no database error.
Everything works fine from the desktop-application side. As mentioned the stored procedures executed directly in the database will work properly. I suppose the the error is somewhere in web-scripting-stuff. So now here are the concrete questions:
Why would the stored procedure not work (properly) when adding a new column to the database (it is there) and no syntax errors in the stored procedures or vbscript?
Why the sqlcmd.Execute stops working when adding a outparameter to the insert stored procedure? The try-block in the stored procedures includes everything between "AS BEGIN" and "END" having the catch-block directly before "END". Syntax is here also correct.
try to catch the error at the asp end.
On Error Resume Next
sqlcmd.Execute
for each objerr in yourconnection.Errors
Response.write objerr.Description & "<br/>"
next
On Error GoTo 0
Please check this link:
ADO Connection Object Errors Collection

MySQL Stored Procedure Call from SSRS through ODBC

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 .

Getting SQL stored procedure results into data.frame format using RODBC

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.