Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where''d my Datasession go?

Status
Not open for further replies.

BPeisch

Programmer
Oct 19, 2003
464
US
I've run into a really strange problem. I've got this chunk of code in my app:
Code:
 * There shouldn't be anything open in any datasession
 * Make sure there isn't
 CLOSE DATABASES ALL
 ASESSIONS(aDataSessions)
 FOR i = 1 TO ALEN(aDataSessions,1)
    SET DATASESSION TO (aDataSessions[i])
    CLOSE TABLES ALL
 ENDFOR 
 SET DATASESSION TO 1		&& go back to the default datasession
The above code is producing an array with 5 items in it. The problems is, when I enter the loop, it's blowing up on the fourth item with the error "Session number is invalid". If I suspend and do a SET command at that point, I don't see a datasession 4 in the dropdown. If it isn't there, how did ASESSIONS find it?


-BP (Barbara Peisch)
 
I've found a workaround for this problem. I found if I did a SET command before the loop, it shows a datasession 4 that it's calling "Unknown". Doing a SET DATASESSION TO any other datasession will make it disappear, so I just SET DATASESSION TO 1 before the call to ASESSIONS.

What I'm wondering is why it's showing the unknown datasession at all? The form that used to have that datasession used a private datasession and didn't call another form that used a default datasession (the biggest culprit for causing "Unknown" datasessions).


-BP (Barbara Peisch)
 
Maybe using a private data session is akin to using a DEFINE WINDOW statement, as in:

DEFINE WINDOW MyWindow FROM 1,1 TO 100,100

The window is there, there's an hWnd value, but since it doesn't have a form.name, the name == "". (Unless of course you give it a name with _screen.form(1).name = 'Whatever')

Just kind of thinking aloud here.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Hi Dave,

It may be something along those lines, but not quite. All the forms in this app seem to be causing this problem, and I've set the Name property for all the forms via the property sheet. While the form is open, the datasession looks normal in the Data Session window. I suspect the problem has something to do with the fact that I've set AutoClose tables to .F. and close everything via code in the form's Destroy method. Somehow, the datasession itself isn't getting closed. FWIW, I did try SET DATASESSION TO 1 after closing everything in the form's Destroy, but the form's datasession is still alive at that point, so it didn't solve the problem.


-BP (Barbara Peisch)
 
Barb,
I haven't got any real suggestions here (I've been on vacation so I missed the discussion), but we've been using this CLOSEALL routine successfully. Note: It was written back in 6.0, but seems to work just fine in 7/8.
Code:
* Program....: CLOSEALL.PRG
* Version....: 1.0
* Author.....: ** Richard G Bean **
* Date.......: October 1, 2001
* Compiler...: Visual FoxPro 06.00.8961.00 for Windows
* Abstract...: Closes all tables/cursors in All datasessions and sets DATASESSION to 1
* Changes....:

LOCAL lnI, llCloseFiles, lcSvOnError
PRIVATE llValidDataSession && so ON ERROR Routine can reset

llCloseFiles = .T.

* Rollback all transactions.
do while txnlevel() > 0
	rollback
enddo while txnlevel() > 0

lcSvOnError = ON("ERROR")
* Go through all data sessions and revert and close all the tables
on error DO close_error WITH ERROR(), MESSAGE(), MESSAGE(1), PROGRAM(), LINENO()
** Note: IN VFP 7.0 will use ASESSIONS() to drive this loop **
for lnI = 2 to 50 && probably too many, but just to make sure
   llValidDataSession = .T.
   set datasession to (lnI)
   if llValidDataSession
      RevertTables(llCloseFiles)
   endif llValidDataSession
next lnI
* Revert all tables/cursors in the default data session.
set datasession to 1
RevertTables(llCloseFiles)
ON ERROR &lcSvOnError

RETURN

*!*****************************************************************************
*!
*!      Procedure: CLOSE_ERROR
*!
*!*****************************************************************************
PROCEDURE close_error
PARAMETERS zerror, zmess, zmess1, zprog, zlineno
PRIVATE    zerror, zmess, zmess1, zprog, zlineno

DO CASE
CASE zerror = 1540 && Invalid Datasession
   llValidDataSession = .F.
   RETURN
	
CASE zerror = 0 AND zmess = "Session number is invalid." && Invalid Datasession
   llValidDataSession = .F.
   RETURN

OTHERWISE
   ** Should NEVER happen <g>
   ON ERROR	* && kill so we don't go looping
   HIDE WINDOW ALL
   SET DATASESSION TO 1
   ACTIVATE WINDOW SCREEN TOP
   CLEAR
   ? ' '
   ? 'Error number: ' + LTRIM(STR(zerror))
   ? 'Error message: ' + zmess
   ? 'Line of code with error: ' + zmess1
   ? 'Line number of error: '+ LTRIM(STR(zlineno))
   ? 'Program with error: ' + zprog
   ? ' '
   WAIT WINDOW &quot;&quot; NOWAIT
   WAIT CLEAR
   MESSAGEBOX('An Unexpected Fault Has Occurred - Program Terminating'+chr(13) ;
     +'-- Please Note the Information Above --')
   CLEAR EVENTS
ENDCASE

RETURN TO MASTER

*!* EOP: CLOSEALL.PRG
 
Hi Rick,

I don't think your CloseAll routine is going to help my situation. There aren't any transactions in progress or any changes pending at all. I just simply opened a form and closed it again and got the bad datasession.

Thanks for the input.


-BP (Barbara Peisch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top