How to use print statement in sybase stored procedure when calling the stored procedure from application - sybase

I am using powerbuilder with Sybase ASE database. I am calling a stored procedure while doing an update from my application but I am getting an error in the stored procedure. I want to put some print statements in the stored procedure to check what the error is. How can I see the output of this print statement? How can I log the stored procedure?
Thanks in advance
Sharmistha

There is no log of these print statements and they are not considered part of the result set. They are in the same channel as the Sybase ASE error messages.
They should be returned to PowerBuilder, in the SQLCA, sqlerrortext is the field.
That's not how I used to debug stored procedures though. I found it easier to capture the parameters being passed to the stored procedure and use Sybase's ISQL command line tool, not the Java GUI, to see the error messages.

You can use function which will return the status code. Add "ON EXCEPTION RESUME" clause inside function and return global variable ##error to your application.

Use a custom error logging procedure to store data in a log table and read errors from it during or after execution.
Alternatively, you can try the PRINT statement inside the procedure to see if you can get the stdout output into PB.

Thank you all, I added some logs in powerbuilder instead to check for my problem.

Related

Error in SP while translating from Oracle to Snowflake

I am translating procedure from Oracle to Snowflake and getting an error:
The procedure is:
https://github.com/santas-little-helper-13/sql/blob/main/sp.sql
I see that ":" is missed when using variables in a SQL statement or assigning the result of a SQL statement to a variable. Please check this part:
https://docs.snowflake.com/en/developer-guide/snowflake-scripting/variables.html#using-a-variable-in-a-sql-statement-binding
https://docs.snowflake.com/en/developer-guide/snowflake-scripting/variables.html#setting-variables-to-the-results-of-a-select-statement
This is a long SP so you may probably hit other errors. Good luck with the rest of the code.

How to include code that creates stored procedure in database script generated from model

Is it even possible? I tried to update model from DB where I have my stored procedure, but it still does not help in what I want to get,i.e. call to create procedure in the output sql script.
It appears that it is pretty much easy as one can add code that creates stored procedure in the 'tt' file as it is said here: http://msdn.microsoft.com/en-us/data/gg558520.aspx

How to call procedures directly from interactive sql

Guys I'm trying to do some checking on a database domains and in order to do that I need to call and see directly substr procedure. Yet I'm getting an error that this procedure hasn't been found. How so? This is supposed to be built-in procedure. How can I call it and get result from it, directly in interactive sql?
First of all in Sybase ASE it is substring and not substr and it is a function so you need to use the select or something like that to run this..
try below
select substring('0000',1,2)

How to access data using VBSCRIPT from a stored procedure which contains values in Temp table?

for testing purpose I wrote a VBscript which will fetch values from Sybase by executing a stored procedure which contains values in temp table. When I run the script I get the following errors ,
"Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record."
or
"Item cannot be found in the collection corresponding to the requested name or ordinal."
Somewhere when I was googling I found that , the above error message will be shown when we use temp table in stored procedure, if that is the reason , then how can I access data via VBscript by executing the stored procedure ??
I am using QTP to run VBScript
I don't know Sybase as well but it sounds like the recordset you return either has field names different than what you are expecting OR its not even there.
I assume you are inserting into the temp table and then eventually selecting from it to return the values.
If sybase supports it, use a Set NOCOUNT On at the beginning of your stored proc.
You likely are getting multiple recordsets back and the first one isn't the one you want.

"could not find stored procedure"

I am maintaining a classic ASP website that has a SQL Server 2005 backend. For a small piece of new functionality I wrote a stored procedure to do an insert. This is the only user stored procedure in the database.
When I attempt to call the stored procedure from code I get the following error:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Could not find stored procedure 'InsertGroup'.
/newGroup.asp, line 84
The DB uses SQL Server authentication. When I connect to the DB server in Visual Studio using the same user/pw as in the connection string the stored procedure is not visible but all tables are.
The user has datareader and datawriter roles and explicit execute permission on the stored procedure.
What am I missing?
UPDATE: My apologies, the server admin misinformed me that it was a 2000 server when it is actually a 2005 server (running on Windows Server 2003 x64).
Walk of shame:
The connection string was pointing at the live database. The error message was completely accurate - the stored procedure was only present in the dev DB. Thanks to all who provided excellent answers, and my apologies for wasting your time.
You may need to check who the actual owner of the stored procedure is. If it is a specific different user then that could be why you can't access it.
Sometimes this can also happen when you have a stored procedure being called with parameters. For example, if you type something like:
set #runProc = 'dbo.StoredProcedure'
exec #runProc
This will work, However:
set #runProc = 'dbo.StoredProcedure ''foods'''
exec #runProc
This will throw the error "could not find stored procedure dbo.StoredProcedure 'foods'", however this can easily be overcome with parantheses like so:
set #runProc = 'exec dbo.StoredProcedure ''foods'''
exec (#runProc)
make sure that your schema name is in the connection string?
There are 2 causes:
1- store procedure name
When you declare store procedure in code make sure you do not exec or execute keyword
for example:
C#
string sqlstr="sp_getAllcustomers";// right way to declare it.
string sqlstr="execute sp_getAllCustomers";//wrong way and you will get that error message.
From this code:
MSDBHelp.ExecuteNonQuery(sqlconexec, CommandType.StoredProcedure, sqlexec);
CommandType.StoreProcedure will look for only store procedure name and ExecuteNonQuery will execute the store procedure behind the scene.
2- connection string:
Another cause is the wrong connection string. Look inside the connection string and make sure you have the connection especially the database name and so on.
I had:
USE [wrong_place]
GO
before
DECLARE..
Could not find stored procedure?---- means when you get this.. our code like this
String sp="{call GetUnitReferenceMap}";
stmt=conn.prepareCall(sp);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
currencyMap.put(rs.getString(1).trim(), rs.getString(2).trim());
I have 4 DBs(sample1, sample2, sample3) But stmt will search location is master Default DB then we will get Exception.
we should provide DB name then problem resolves::
String sp="{call sample1..GetUnitReferenceMap}";
One more possibility to check. Listing here because it just happened to me and wasn't mentioned;-)
I had accidentally added a space character on the end of the name.
Many hours of trying things before I finally noticed it. It's always something simple after you figure it out.
I had the same problem. Eventually I found why. I used a code from web to test output of my procedure. At the end it had a call to Drop(procedure) so I deleted it myself.
If the error message only occurs locally, try opening the sql file and press the play button.

Resources