powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Как заставить работать транзакцию?
4 сообщений из 4, страница 1 из 1
Как заставить работать транзакцию?
    #32325637
AlexSV
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Не сильно копал Access (XP), но нашел что есть у Connection методы работы с транзакциями. Пробую делать примерно следующее:

On Error GoTo ErrorHandler
'
CurrentProject.Connection.BeginTrans
'
CurrentProject.Connection.Execute ("INSERT INTO T1 (Code, Name) values (1, 'val1')")
CurrentProject.Connection.Execute ("INSERT INTO T1 (Code, Name) values (2, 'val2')")
'
CurrentProject.Connection.CommitTrans
'
Exit Sub
'
ErrorHandler:
CurrentProject.Connection.RollbackTrans
MsgBox Err.Description

В ошибку вываливается, что необходимо сначала открыть транзакцию...
В чем тут грабли?
...
Рейтинг: 0 / 0
Как заставить работать транзакцию?
    #32325723
(c)VIG
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Скорее всего ошибка ошибка генерится уже после CommitTrans .
Попробуй что то типа

CurrentProject.Connection.CommitTrans
on error goto 0 ' или on error goto ErrHandler2

Exit Sub
ErrorHandler:
.........
ErrHandler:
' здесь обработчик ошибок после CommitTrans
...
Рейтинг: 0 / 0
Как заставить работать транзакцию?
    #32325742
Фотография Senin Viktor
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Проблема в другом и это на форме уже было. Нельзя таким образом открывать транзакцию ибо
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
Knowledge Base  

ACC2000: Error Using CurrentProject.Connection in TransactionsPSS ID Number:  223213 

Article Last Modified on  5 / 13 / 2002 
 --------------------------------------------------------------------------------
 
The information in this article applies to:
Microsoft Access  2000 
 --------------------------------------------------------------------------------
 
This article was previously published under Q223213
Advanced: Requires expert coding, interoperability, and multiuser skills. 

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp). 


SYMPTOMS
If you use the CommitTrans or RollbackTrans methods directly with the 
CurrentProject.Connection object, you may receive one of the following errors: 
You tried to commit or rollback a transaction without first beginning a transaction. 
-or- 
No transaction is active. 

CAUSE
Each time the CurrentProject.Connection object is used, it has a different pointer 
to the connection. In effect, the instance or pointer to that object is temporary. 
This is why you see no error on CurrentProject.Connection.BeginTrans, but you do 
receive an error once you try to commit or rollback the transaction. 

RESOLUTION
Microsoft provides programming examples for illustration only, without warranty 
either expressed or implied, including, but not limited to, the implied warranties of 
merchantability and/or fitness for a particular purpose. This article assumes that 
you are familiar with the programming language being demonstrated and the tools 
used to create and debug procedures. Microsoft support professionals can help 
explain the functionality of a particular procedure, but they will not modify these 
examples to provide added functionality or construct procedures to meet your 
specific needs. If you have limited programming experience, you may want to 
contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at 
( 800 )  936 - 5200 . For more information about Microsoft Certified Partners, please 
visit the following Microsoft Web site: 
http://www.microsoft.com/partner/referral/
...
CAUTION: If you follow the steps in this example, you modify the sample database 
Northwind.mdb. You may want to back up the Northwind.mdb file and follow these 
steps on a copy of the database.

Set an object variable once to CurrentProject.Connection and use it for your 
transaction processing, such as in the following example. Here,  "c"  is the 
Connection object used for transactions:

NOTE: The sample code in this article uses Microsoft ActiveX Data Objects. For 
this code to run properly, you must reference the Microsoft ActiveX Data Objects 
 2 .x Library (where  2 .x is  2 . 1  or later.) To do so, click References on the Tools 
menu in the Visual Basic Editor, and make sure that the Microsoft ActiveX Data 
Objects  2 .x Library check box is selected. 

Open the sample database Northwind.mdb.
In the Database windows, click Modules under Objects, and then click New.
Type the following code in the new module:
Sub tstConnectionObj()

   Dim c As ADODB.Connection
   Dim rs As ADODB.Recordset

   Set c = CurrentProject.Connection
   Set rs = New ADODB.Recordset

   rs.Open  "Categories" , c, adOpenDynamic, adLockOptimistic

   c.BeginTrans
   rs.Fields( 1 ) =  "Drinks" 

   rs.Update
   MsgBox  "Updated field to "  & rs.Fields( 1 ) &  "." 

   c.RollbackTrans
   rs.Requery
   MsgBox  "Rolled back field to "  & rs.Fields( 1 ) &  "." 

End Sub
					
In the Immediate window, type the following and press ENTER: 
tstConnectionObj
						
Note that you see the following message:
Updated field to Drinks. 

Click OK on the message. Note that you see the following message:
Rolled back field to Beverages. 

Click OK on the message.
MORE INFORMATION
Steps to Reproduce Behavior
Open the sample database Northwind.mdb.
In the Database windows, click Modules under Objects, and then click New.
Type the following code in the new module:
Sub tstCurrentProj()

   Dim rs As ADODB.Recordset

   Set rs = New ADODB.Recordset

   rs.Open  "Categories" , CurrentProject.Connection, adOpenDynamic, _
     adLockOptimistic

   CurrentProject.Connection.BeginTrans
   rs.Fields( 1 ) =  "Drinks" 
   rs.Update
   MsgBox  "Updated field to "  & rs.Fields( 1 ) &  "." 

   CurrentProject.Connection.RollbackTrans
   MsgBox  "Rolled back field to "  & rs.Fields( 1 ) &  ".

End Sub
					
In the Immediate window, type the following and press ENTER: 
tstCurrentProj
						
Note that you see the following message:
Updated field to Drinks. 

Click OK on the message. 

Note that you see the first error message mentioned in the " Symptoms" section of this article.

...
Рейтинг: 0 / 0
Как заставить работать транзакцию?
    #32325746
(c)VIG
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Виктор,ты как всегда,прав.Тем не менее мой совет остается в силе.
Кстати вот типовая схема обработки транзакции о Гетцу
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
On Error Goto ErrHandler
Dim cnn as ADO.Connection
Dim fInTrans as Boolean
fInTrans=false
Set Cnn=CurrentProject.Connection
'...............................
cnn.BeginTrans
fInTrans=True
' .... последовательность изменения данных
cnn.CommitTrans
fInTrans=False
'...........другие действия
ErrHandler:
If fInTrans
  cnn.RollbackTrans
End If
' Дальнейшая обработка ошибок
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Microsoft Access [игнор отключен] [закрыт для гостей] / Как заставить работать транзакцию?
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]