How to close a DB2 cursor from OLEDB client? - db2

I have client utility that uses OLEDB to call a DB2 stored procedure. Inside the stored a procedure a cursor is opened so my utility can read record sets. Everything works fine but after a while of calling the same procedure over and over again, DB2 eventually throws an error that is related to the cursor being left open. Is there a sql command in DB2 to close the last used cursor or something similar?

I can't see how to do it from the client, but in the sp the code should be calling
Close CursorName;. Can you not update the procedure?
See here for an example.

Related

How to find Who did some query on the database and when?

I have a SQL Server 2008 R2 with a database in it.
How to find a certain query that was executed and from what IP ?
I have tried to go through the transaction logs but I cant understand nothing there.
You should use SQL Server Profiler. It's usually installed by default - look in the SQL Server folder on the Start Menu. When you open it, start a new trace and select the database. In the Trace Properties dialog choose the TSQL template. This will then record all the queries running on the database, along with a whole lot of other stuff. It's not massively easy to track stuff down in here, but look for the BatchStarting events to find the SQL that gets run. Then you should run the procedure sp_who2 on the database so you can match up SPIDs in the profiler to logins.

How to execute reports which involve a stored procedure calling out to a linked server

I wrote a stored procedure that calls openquery to a linked server to get data from a remote postgresql server and fill a table with that data. This is working fine. The stored procedure needs 3 parameters.
When I try to call the stored procedure from Report Builder 3.0 gives me error
7350 (cannot get the column OLE DB provider MSDASQL from linked server "name").
I already verify the allow in-process parameter in MSDASQL.
I can't find a solution for this. If I run the stored procedure from Mgmt Studio, it works fine. I'm using SQL Server 2012.
The report only have to show the file data by row. I can run the stored procedure and the report separately and works but I have to do this manually, my requirement needs a report subscription, so have to be automatic.
Any idea how to solve this or a workaround?
PD: sorry for my english, and thank you in advance.
Well I had to make separates works, so create a job that run the store procedure, generate the info on a table, and then run report reading the info from the table. This works.
Thank you all.

Behaviour of fetchrow_hashref in Perl

I am trying to execute a procedure from Perl and store the results in a text file (on Windows). I am using DBI's
fetchrow_hashref() to fetch row results. The stored procedure that I am trying to execute returns more than 5 million rows. I want to know the functionality "behind-the-scene" - particularly what happens during the
fetchrow_hashref() call. e.g. Perl executes the procedure, the procedure returns all the impacted rows, keeps it in a pool (either on Database side or the calling machine side?) and then Perl selects the rows from resultset one by one. Does it happen that way or something else?
This is a difficult question to answer as you've not said which Perl database driver you are using. I'm assuming you are using DBD::ODBC and the MS SQL Server ODBC Driver in this answer.
When you call prepare on the SQL calling the procedure the ODBC driver sends it to MS SQL Server where the procedure is parsed. On calling execute the procedure is started (how you progress through the procedure depends on a lot of things). Assuming the first thing in your procedure is a select a cursor will be created for the query and MS SQL Server will start sending the rows back to the ODBC Driver (it uses the TDS protocol). In the mean time DBD::ODBC will make ODBC calls to the driver which tells it there is a result-set (SQLNumResultCol returns a non zero value). DBD::ODBC will then query the driver for the types of the columns in the result-set and bind them (SQLBindCol).
Each time you call fetchrow_hashref, DBD::ODBC will call SQLFetch, the ODBC driver will read a row from the socket and copy the data to the bound buffers.
There are important things to realise here. Mostly MS SQL Server will write a lot of rows initially to the socket even though the ODBC driver is probably not reading them yet. As a result, if you close your statement the driver has to read a lot of rows from the socket and throw them away. If you use a non standard cursor or enable Multiple Active Statements in the driver then rows are sent back to the driver one at a time so the ODBC driver can ask the server to move forward, backward in the result-set or request a row from result-set 1 then result-set 2.
There are other areas a little unusual when using procedures like whether nocount is enabled or not and you progress through your procedure statements using SQLMoreResults (odbc_more_results). Also, the output parameters in a procedure are no available until SQLMoreResults returns false.
You may find Multiple Active Statements (MAS) and DBD::ODBC of some interest to you or may some of the other articles. You may also want to read about the TDS protocol.

Debug DB2 stored proc

I am using IBM DB2 with Toad. I have a stored procedure that I need to debug.Any tutorial or videos on how to debug a stored procedure ? Echo statement won't work. One way would be to create a temp table, dump data in to it and open cursor at the end. But any alternative to this ?
I can't answer how to do this with Toad, but the (free) IBM Data Studio includes the ability to interactively debug stored procedures. You can set breakpoints, step through your procedure, see variable values during execution, etc.

Entity Framework see SQL sentence when calling stored procedure

Is there a way to see the underlying SQL sentence when executing a stored procedure in Entity Framework (3.5)?
To use the stored procedure I did from the diagram: Add, Function Import… etc
Thanks
UPDATE 1
I downloaded 'AnjLab Sql Profiler' from.
http://code.google.com/p/sqlexpressprofiler/downloads/list
And was able to see that the stored procedure is executed correctly.
You can use any type of database profiler - for example SQL profiler for SQL server or you can use either EFTracingProvider or any EF profiler (these tools are usually commercial). Here is whole article about these techniques.