Thanks Mike. But myForm.DataSession is set to 1 (Default Data Session)
I'm worried is there any coding wrong.
In myform.load, I write:
IF USED("myCursor")
REQUERY("myCursor")
ELSE
thisform.DataEnvironment.NewObject("myObject", "myCAClass")
thisform.DataEnvironment.myObject.CursorFill()
ENDIF
And thisform.DataEnvironment.AutoCloseTables is set to .F.
In myCAClass, I only change the code in CursorFill as follows:
LPARAMETERS tlUseCursorSchema, tlNoData, tuOptions, toSource
LOCAL lWasError, lcSQLConnect
TRY
lWasError = .F.
lcSQLConnect = [MyConnectString]
WITH this
.Name = [MyCAName]
.Alias = [MyCursor]
.Tables = [MySQLTable]
.SelectCmd = [SELECT MyFields FROM MySQLTable WHERE MyCondition]
.CursorSchema = […]
.KeyFieldList = [idnbr]
.UpdateNameList = […]
.UpdatableFieldList = […]
.AllowDelete = .T.
.AllowInsert = .T.
.AllowUpdate = .T.
.BatchUpdatecount = 1
.BufferModeOverride = 5
.CompareMemo = .T.
.DataSourceType = [ODBC]
.DataSource = SQLSTRINGCONNECT(lcSQLConnect)
.FetchAsNeeded = .T.
.FetchMemo = .T.
.FetchSize = 100
.MaxRecords = -1
.SendUpdates = .T.
.UpdateType = 1
.UseCursorSchema = .T.
.UseMemoSize = 255
.UseTransactions = .T.
.WhereType = 3
ENDWITH
WAIT CLEAR
CATCH
WAIT CLEAR
lWasError = .T.
ENDTRY
IF lWasError
AERROR(laError)
MESSAGEBOX("CursorAdapter Error" + CR + CR + laError(2), MB_ICONSTOP, SEM_LOC)
RETURN .F.
ELSE
RETURN DODEFAULT(tlUseCursorSchema, tlNoData, tuOptions, toSource)
ENDIF