Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Tim Lawrence
  Where is Tim Lawrence?
 Duluth
 Georgia - United States
 Tim Lawrence
 Tags
Subject: Invalid connection handle
Thread ID: 268990 Message ID: 268990 # Views: 30 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Thursday, July 15, 2010 9:01:23 PM         
   


Ok Gang,

I previously had posted about ODBC connections. This is in conjuction with that.

If I create a CursorAdapter, set all the properties, and perform a CursorFill(), all is right with the world. If I delete the connection after the fill and then re-create it if I want to do a CursorRefresh, BOOM! "Invalid Connection Handle" from AERROR(). I have to do a CursorFill again before i can do a CursorRefresh. Here's a sample of the test platform:

SQLDISCONNECT(0)
CLEAR 
RELEASE oca
PUBLIC oCA as Cursoradapter, ;
	oConn as Integer
oCA = CREATEOBJECT('cursoradapter')
oCA.Alias = 'PT'
oCA.BufferModeOverride = 5
oCA.CursorSchema = [name c(30), systemkey c(8), cell_phone c(12)]
oca.UseDeDataSource=.f.
oca.DataSource = SQLSTRINGCONNECT([DRIVER=SQL Native Client;] + ;
						[SERVER=server;] + ;
						[Trusted_Connection=Yes;] + ;
						[DATABASE=mydata;])
SQLSETPROP(oCA.DataSource,"Transactions",2)						
oCA.DataSourceType='ODBC'						
oCA.KeyFieldList='systemkey'
oCA.SelectCmd = [select top 100 name, systemkey, cell_phone from pt (nolock) where systemkey = '77777777']
oCA.Tables = 'pt'
oCA.UpdatableFieldList= [name, systemkey, cell_phone]
oCA.UpdateNameList=[name pt.name, systemkey pt.systemkey, cell_phone pt.cell_phone]
oCA.UseCursorSchema = .t.
? oca.CursorFill(.F.,.f.)
BROWSE LAST NOWAIT 
*!*	SQLIDLEDISCONNECT(oCA.DataSource)
? SQLGETPROP(oca.DataSource,"ODBChdbc")
SQLDISCONNECT(oCA.DataSource)
? cell_phone
REPLACE cell_phone WITH TRANSFORM(val(cell_phone) + 1)
oCA.DataSource = .null. 
oca.DataSource = SQLSTRINGCONNECT([DRIVER=SQL Native Client;] + ;
						[SERVER=server;] + ;
						[Trusted_Connection=Yes;] + ;
						[DATABASE=mydata;])

? SQLGETPROP(oca.DataSource,"ODBChdbc")
lsuccess = .f.
IF TABLEUPDATE(0, .t., 'pt', 'tst')
	lsuccess = .t.
	? 'SQLCOMMIT: '
	?? SQLCOMMIT(oCA.DataSource)
	? 'CursorFill: '
	?? oca.CursorFill(.f.)
	? 'CursorRefresh: '
	?? oca.CursorRefresh()
	? 'Requery() :' 
	?? REQUERY('pt')
ELSE
	TABLEREVERT(.t.,'pt')
ENDIF  
MESSAGEBOX('Update ' + IIF(lsuccess, 'Succeeded', 'Failed' + CHR(13) + tst[2]))
MESSAGEBOX(ASQLHANDLES(tst))
SQLDISCONNECT(0)


So has anyone else come across this or can explain the behavior? My reason for asking is tied back to my other post Message ID: 268165 where the requirement is to connect, query, disconnect...

ENTIRE THREAD

Invalid connection handle Posted by Tim Lawrence @ 7/15/2010 9:01:23 PM
RE: Invalid connection handle Posted by Borislav Borissov @ 7/15/2010 9:09:32 PM
RE: Invalid connection handle Posted by Tim Lawrence @ 7/15/2010 10:20:29 PM