1. Paul Murray
  2. PowerBuilder
  3. Saturday, 26 August 2017 13:37 PM UTC

Greetings All,

I have a PowerBuilder 12.5 application with code in a timer event that periodically looks for records to process.  While not a PowerBuilder issue, we have been having some trouble with a database where the connection times out or sometime you just cannot connect on the first go try (or the second).  Other people are working on ferreting out the issue with the database.

In the meantime, I need a way to reliably check that the database is connected and reconnect if necessary.

In the code in the timer event, I have the following:

timer(0)

of_connect()

long connected

connected = dw_1.settransobject(sqlca)

if connected <> 1 then

                of_disconnect()

                of_connect()

                dw_1.settransobject(sqlca)

end if

dw_2.settransobject(sqlca)

…processing…

of_disconnect()

timer(15)

Nevertheless, when I check on the application after a few hours, I see the following error in a popup window that causes the application to halt until human intervention comes along (like me restarting the application).   >: (  

I would really appreciate it if someone can kindly suggest a way to code to continually retry the connection as it seems sporadic while suppressing the exception window.  

Thanks All!!  Paul

MESSAGEBOX EXCEPTION:

Connection failed:
SQLState '01000'
SQL Server Error: 10060
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (PreLoginHandshare()).
Connection failed:
SQLState: 08001
SQL Server Error: 11
[Microsoft][ODBC SQL Server Driver][DBNETLIB]General network error.  Check your network documentation.

'OK' button

René Ullrich Accepted Answer Pending Moderation
  1. Monday, 28 August 2017 08:59 AM UTC
  2. PowerBuilder
  3. # 1

Try to add the ConnectOption SQL_DRIVER_NOPROMPT.

SQLCA.DBParm = "ConnectString='...',ConnectOption='SQL_DRIVER_CONNECT,SQL_DRIVER_NOPROMPT'"

Maybe this helps to prevent the error message.

Comment
There are no comments made yet.
Daniel Vivier Accepted Answer Pending Moderation
  1. Saturday, 26 August 2017 17:54 PM UTC
  2. PowerBuilder
  3. # 2

Which statement in your code is generating that MessageBox?

You can check whether a Transaction object was EVER successfully connected by checking whether its DbHandle() method returns > 0. However, if it WAS connected then lost the connection, that value doesn't change.

I'm not convinced that SetTransObject() returns -1 if the DB is disconnected. My guess is you have to try doing an action on the DW that executes SQL before you will get an error.

From the thread https://archive.sap.com/discussions/thread/3411329, it seems that the best way to know whether a Transaction object is connected is to try to run a trivial direct SQL on it, like:

Execute Immediate "Select 1 from DUMMY"; // use whatever dummy single-row or pseudo- table your DB contains, or "Select 1" if your DB allows that
if sqlca.sqlcode <> 0 then
    // you aren't connected
end if

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.