cancel
Showing results for 
Search instead for 
Did you mean: 

Restart() function crashing

Former Member
0 Kudos

When the Restart() function executes, the program fatal crashes with "Sybase Powerbuilder 12.5 has stopped working"

I set a breakpoint at the function, but when I try to step into it, it crashes.

Restart documentation: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc37781.1250/html/psref/BFC...

Any help or suggestions?

PowerBuilder Classic Version 12.5.2 Build 5583

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Stephen;

Note1: Restart ( ) should only be used when running your PB application from an EXE.

Note2: Running from the PB IDE will make your PB application a sub-task of the IDE. Thus, a Restart ( ) will crash PB.

Note3: If you issue a Restart on a failed DBMS connection, it will attempt to perform a Commit & Disconnect. So make sure your application ignores errors in this area if a restart is in progress.

HTH

Regards ...Chris

Former Member
0 Kudos

Thanks again Chris! You guys know so much! Im glad I joined the forums!

I do wish this knowledge was better documented by Sybase, but anyways, it does make sense.

I will test as .exe and then accept your answer

-Stephen

Former Member
0 Kudos

I have deployed the application and am running the .exe file, but when it hits the Restart() function it still does a fatal crash - "abc.exe has stopped working"

A. I tried putting a try/catch around the Restart() function and a messagebox for its return value, but it never returns from the Restart() nor does it throw an exception.

B. I also tried running the .exe as administrator.

C. I also tried putting the Restart() into its own function.

Former Member
0 Kudos

What OS version? What database are you connected to?

What is the app doing before the Restart? What event calls it?

I'm thinking that there is something going on that is unfinished that you are interrupting.

Former Member
0 Kudos
What OS version? What database are you connected to?

Windows 8.1 Pro

Sql Server 2005

PowerBuilder Classic Version 12.5.2 Build 5583


What is the app doing before the Restart? What event calls it?

Before it is called, a physical network disconnect occurs and it enters the DBError event of the parent transaction object. It than loops through disconnect, connect, sleeping 10 seconds, and then testing the database connection until the database connection works. After that, a Restart() is called.

** Manually disconnect network connection **

dw_abc.Retrieve()

** General Network Error messagebox pops up **

uo_transaction - DBError()

{

if code = 11 then

  messagebox("Reconnecting to database...", "")

  do

    this.test_sql() // function that runs simple SQL to test database connection

    if this.SQLCode < 0 then

      sleep(10)

      DISCONNECT using this;

      CONNECT using this;

    end if

  loop while this.SQLCode < 0

  messagebox("Connected! - Restarting abc...", "")

  Restart()

end if

return code

}

** I get the last message box and after clicking it the application fatally crashes at Restart() - "abc.exe has stopped working"**

arnd_schmidt
Active Contributor
0 Kudos

Hi Stephen,

I doubt if that is the right usage of the restart() function.

You are in the middle of a script execution "return code" and not in the idle event,

so there is no empty call stack 😞

Eventually posting the restart() function may work.

Arnd

Former Member
0 Kudos

I just checked the help for Restart and it says:

Stops the execution of all scripts, closes all windows (without executing the scripts for the Close events), commits and disconnects from the database, restarts the application, and executes the application-level script for the Open event.

So it does not run the close events. I do however agree with your suggestions. I would put the Sleep after the Disconnect as well.

Former Member
0 Kudos

Thanks for the update Roland!

I would suggest that Ted go one step further though and remove all DML that he is using in the DBError event (and skip your Sleep suggestion)!

Instead, just issue the message, then run a DBCancel ( ), post a UE* and then exit the script immediately by issuing a RETURN 3 command.

* - Put the restart ( ) in the User Event.

Regards ... Chris

Answers (2)

Answers (2)

Former Member
0 Kudos

Hey guys, thanks for all of your input, after talking with my boss, we went a different route (with code already existing on another project).

Using an external function placed in "Global External Functions"

FUNCTION ulong GetCurrentDirectoryA(ulong BufferLen, ref string currentdir) LIBRARY "Kernel32.dll"

I am able to get the current directory of the running exe and then using WScript.Shell, I am able to do my own restart. With the added benefit that I can auto login the user back into the system.

string ls_curdir

ulong l_buf

l_buf = 2048

ls_curdir = space(l_buf)

GetCurrentDirectoryA(l_buf, ls_curdir)  // return double byte

string ls_full_path

ls_full_path = ls_curdir + "\" + string(abc.AppName) + ".exe" + " " + gs_username + ", " + gs_password

CONSTANT integer NORMAL = 1

CONSTANT boolean WAIT = FALSE

integer  li_rc = 0

OleObject wsh

wsh = CREATE OleObject

li_rc = wsh.ConnectToNewObject( "WScript.Shell" )

li_rc = wsh.Run(ls_full_path, NORMAL, WAIT)

HALT CLOSE

arnd_schmidt
Active Contributor
0 Kudos

Much better to do a "real" restart, but be carefull with passwords in command lines (can be a small security issue).
And by the way, PB 12.5 has a build-in GetCurrentDirectory ( ).

Former Member
0 Kudos

Hi Stephen;

FYI ....

1) GetCurrentDirectoryA should be GetCurrentDirectoryW

2) You really should use the API - GetModuleFileNameW

  - the current directory may not be where the EXE actually came from!

  =>  http://msdn.microsoft.com/en-ca/library/windows/desktop/ms683197%28v=vs.85%29.aspx

Good luck!

Regards ... Chris

Former Member
0 Kudos

Hi Stephen,
How exactly did you code this.  I did a simple test along the lines of the documentation.

I put idle(100) in the open event of the application and Restart() in the idle event of the application and it is working just fine.

I tested with 12.5 2511 and 12.5.2 5006.

Ted Zimmerman