1. Venkatesh Guptha
  2. PowerBuilder
  3. Tuesday, 16 July 2024 17:23 PM UTC

We have a SQL Server procedure with 20K lines of code. We will execute the procedure 18 times and syntax is  created dynamically from PowerBuilder. Attached the dynamic query.

If the query is executed from SSMS there is no issue, it is inserting into all tables for all the input values we give.

But from PowerBuilder it is executing only 4 times/sometimes 6/sometimes 7 instead of 18 times. This is really weird issue that we are facing

The same procedure is working fine in Sybase database. After we migrate to SQL Server we are facing the issue. 

We are using PowerBuilder 2017

1/ Do we need to add any DB parms to overcome this issue?

[ODBC]
DBMS=ODBC
Database=database
DBParm="TrimSpaces=1,ConnectString='DRIVER={SQL Server};SERVER=server\server;DATABASE=database;PORT=1435;PROTOCOL=TCPIP;UID=uid;PWD=pwd';PBNewSPInvocation=YES,CallEscape=NO"
User_Id=test

2/ Any other changes need to do to SQL server ?

 

Sample PB Code for Dynamic SQL-

DECLARE @temp_error int
DECLARE @return_code int
DECLARE @return_message varchar(255)
DECLARE @temp_message varchar(255)

execute @return_code = our_stored_procedure1 2345678, 402056421, '0012345', 'testing', 'PEND', ' ', 'GP', 'OURAPP', 'NO', ' ', 'NACCT', 'N', 'N'
SELECT @temp_error = @@error
IF @return_code <> 0
begin
IF @temp_error != 0
begin
SELECT @temp_message = convert(char(5), @temp_error)
end
ELSE
begin
SELECT @temp_message = convert(char(5), @return_code)
end
SELECT @temp_message = @temp_message + '|' +
' our_stored_procedure1 2345678, 402056421, "0012345", "testing", "PEND", '' '', "GP", "OURAPP", "NO", '' '', "NACCT", "N", "N" '
raiserror (50999,16,1, @temp_message)
return

end
execute @return_code = our_stored_procedure 2345678, 'BSCL', 'GP'
SELECT @temp_error = @@error
IF @return_code <> 0
begin
IF @temp_error != 0
begin
SELECT @temp_message = convert(char(5), @temp_error)
end
ELSE
begin
SELECT @temp_message = convert(char(5), @return_code)
end
SELECT @temp_message = @temp_message + '|' +
' our_stored_procedure 2345678, "BSCL", "GP" '
raiserror (50999,16,1, @temp_message)
return

end
execute @return_code = our_stored_procedure 2345678, 'DADD', 'GP'
SELECT @temp_error = @@error
IF @return_code <> 0
begin
IF @temp_error != 0
begin
SELECT @temp_message = convert(char(5), @temp_error)
end
ELSE
begin
SELECT @temp_message = convert(char(5), @return_code)
end
SELECT @temp_message = @temp_message + '|' +
' our_stored_procedure 2345678, "DADD", "GP" '
raiserror (50999,16,1, @temp_message)
return

end

It has become a show stoper for us. Please help to put your thoughts/suggesstions on this. Thank you

 

 

Venkatesh Guptha Accepted Answer Pending Moderation
  1. Friday, 2 August 2024 09:54 AM UTC
  2. PowerBuilder
  3. # 1

Adding -

SET NOCOUNT ON

at the start of the batch did resolved this issue.

 

here is the documentation from Microsoft - 

https://learn.microsoft.com/en-us/troubleshoot/sql/connect/fail-run-large-batch-sql-statements

Comment
  1. Armeen Mazda @Appeon
  2. Saturday, 3 August 2024 16:01 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Thursday, 18 July 2024 05:53 AM UTC
  2. PowerBuilder
  3. # 2

1.  Write to a log file from PB, for each iteration with required details.
2.  Write to a temp table from SP, for each iteration with required details.

Reading / comparing these two details, you can find, whether the issue is in PB code or in SP. 

Happiness Always
BKR Sivaprakash

Comment
There are no comments made yet.
Venkatesh Guptha Accepted Answer Pending Moderation
  1. Wednesday, 17 July 2024 16:25 PM UTC
  2. PowerBuilder
  3. # 3

Hi John Fauss

1/ I have commented the raise error part of the code and the issue still exist

after generating the dynamic query we use like below to execute directly -

 

s_work = "begin tran "
EXECUTE IMMEDIATE :s_work USING i_tr;

FOR l_count = 1 TO l_sql_count

// s_batch_sql will have the dynamic query which I have attached to this thread
EXECUTE IMMEDIATE :s_batch_sql[l_count ] &
USING i_tr;

IF SQLCA.SQLCODE = 0 Thren return true

2/ We can't migrate to the newer version of PB as of now so I can't check this one too

3/ There is restriction from business to not to use the SQL Native client as they want to use the default SQL Server driver that comes with the windows machine. So I can't try this one for our application.

 

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 16 July 2024 20:18 PM UTC
  2. PowerBuilder
  3. # 4

Hi Venkatesh;

  I wonder if this is a SS timeout setting that is affecting the number of SP iterations that you are encountering?  SSMS might be using an EXECUTE IMMEDIATE to override SS timeout settings. I would suggest contacting your DBA Team for these various timeout settings and also what Errors might be present in the SS logs when this issue happens.  HTH

Regards .. Chris

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 16 July 2024 18:43 PM UTC
  2. PowerBuilder
  3. # 5

Hi, Venkatesh -

What version of SQL Server are you using?

Can you please post a code snippet of the PowerScript code that calls the SQL code and checks the result? What is the SQLCA.SQLCode, SQLDBCode and SQLErrText property values when a call is successful and when it fails?

Some suggestions to consider:

  1. Comment out the RAISERROR statements and re-try.
  2. Migrate to a new, supported version of PB, as 2017 has been out of support for a while now.
  3. Use a native SQL Server database interface instead of ODBC. SQL Server Management Studio (SMSS) does not use ODBC. For PB 2017, this means using SQL Server Native Client (SQLCA.DBMS="SNC"). For PB 2019 R3 and newer, use MSOLEDBSQL (SQLCA.DBMS="MSO"). Of course, using a different database interface means using a different set of connection parameters.

In future posts, it will be appreciated if you would please post code snippets of more than a couple of lines using the "Insert/Edit code sample" tool provided by the Community web site toolbar, as this makes your code much easier to read and understand. Review the anchored lead post on the main page of the Q&A forum for more information.

Best regards, John

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.