J
Jean
Hi
We have just recently converted a MSACCESS 97/SQL Server 7.0 app. to
MSACCESS 2002/SQL Server 2000. We have encounter some troublesome code
errors and not sure the cause. Here is one of them.
We have a table "tblMemberPaymentBatch" on SQL Server 2000 that has zero
records. It has a cluster primary key (autonumber) and an index.
Also a temporary working table on the local MDB. (not linked)
"tblwrkPaymentBatch" with primary key setup as well.
All we wanted to do is to execute an Append query (Insert into... Select
....) see below codes, but there is always locks created by the Insert on the
SQL Server that won't go away even with the CommitTrans. The locks never
get released and transaction always got roll back if we just terminate the
app.. There is no error message from the application.
I don't understand why that locks do not go away even if I included the
CommitTrans after the Execute statement.
We have tried to drop and recreated the PK and index, no help. Ran DBCC
CHECKDB, DBCC CHECKALLOC, Update Statistic, no error from the database
server either.
We tried to run the append query from query design, no locks on the
database, the locks only occur when we execute it from the script (part of a
module).
Please help!
Jean
====================================================
Function AddPayments() As Boolean
On Error GoTo AddPaymentsErr
Dim mWS As Workspace
Dim strSQL As String
Dim boolInTrans As Boolean
Set mWS = DBEngine.Workspaces(0)
Set mDB = CurrentDb()
mWS.BeginTrans
'boolInTrans = True
'Append summary record to payment batch tbl
strSQL = "INSERT INTO tblMemberPaymentBatch ( BatchNo, " & _
" bankdate, BatchDate, PaymentTotal, BankID ) " & _
"SELECT tblwrkPaymentBatch.BatchNo,
NumberToDate(Nz([BankDate],0)) AS BDate, " & _
" NumberToDate(Nz([BankDate],0)) AS BDate2, " & _
" Sum(ConvertDollars(Nz([Payment],0))) AS Amt,
tblwrkPaymentBatch.BankID" & _
" FROM tblwrkPaymentBatch " & _
" GROUP BY tblwrkPaymentBatch.BatchNo,
NumberToDate(Nz([BankDate],0)), " & _
" NumberToDate(Nz([BankDate],0)),
tblwrkPaymentBatch.BankID "
mDB.Execute strSQL, dbSeeChanges
mWS.CommitTrans
boolInTrans = False
Call EmptyTable_TSB("", tblName)
AddPayments = True
AddPaymentsExit:
If boolInTrans = True Then mWS.Rollback
Exit Function
AddPaymentsErr:
ErrMsgBox Err.Description, basName & ".AddPayments", Err.Number
AddPayments = False
Resume AddPaymentsExit
End Function
We have just recently converted a MSACCESS 97/SQL Server 7.0 app. to
MSACCESS 2002/SQL Server 2000. We have encounter some troublesome code
errors and not sure the cause. Here is one of them.
We have a table "tblMemberPaymentBatch" on SQL Server 2000 that has zero
records. It has a cluster primary key (autonumber) and an index.
Also a temporary working table on the local MDB. (not linked)
"tblwrkPaymentBatch" with primary key setup as well.
All we wanted to do is to execute an Append query (Insert into... Select
....) see below codes, but there is always locks created by the Insert on the
SQL Server that won't go away even with the CommitTrans. The locks never
get released and transaction always got roll back if we just terminate the
app.. There is no error message from the application.
I don't understand why that locks do not go away even if I included the
CommitTrans after the Execute statement.
We have tried to drop and recreated the PK and index, no help. Ran DBCC
CHECKDB, DBCC CHECKALLOC, Update Statistic, no error from the database
server either.
We tried to run the append query from query design, no locks on the
database, the locks only occur when we execute it from the script (part of a
module).
Please help!
Jean
====================================================
Function AddPayments() As Boolean
On Error GoTo AddPaymentsErr
Dim mWS As Workspace
Dim strSQL As String
Dim boolInTrans As Boolean
Set mWS = DBEngine.Workspaces(0)
Set mDB = CurrentDb()
mWS.BeginTrans
'boolInTrans = True
'Append summary record to payment batch tbl
strSQL = "INSERT INTO tblMemberPaymentBatch ( BatchNo, " & _
" bankdate, BatchDate, PaymentTotal, BankID ) " & _
"SELECT tblwrkPaymentBatch.BatchNo,
NumberToDate(Nz([BankDate],0)) AS BDate, " & _
" NumberToDate(Nz([BankDate],0)) AS BDate2, " & _
" Sum(ConvertDollars(Nz([Payment],0))) AS Amt,
tblwrkPaymentBatch.BankID" & _
" FROM tblwrkPaymentBatch " & _
" GROUP BY tblwrkPaymentBatch.BatchNo,
NumberToDate(Nz([BankDate],0)), " & _
" NumberToDate(Nz([BankDate],0)),
tblwrkPaymentBatch.BankID "
mDB.Execute strSQL, dbSeeChanges
mWS.CommitTrans
boolInTrans = False
Call EmptyTable_TSB("", tblName)
AddPayments = True
AddPaymentsExit:
If boolInTrans = True Then mWS.Rollback
Exit Function
AddPaymentsErr:
ErrMsgBox Err.Description, basName & ".AddPayments", Err.Number
AddPayments = False
Resume AddPaymentsExit
End Function