Write and read uncommitted entry within transaction?
draken
Member Posts: 9
Hi,
The following simplified code is trying to read an uncommitted record, from Navision 4, using ADO:
The item table I'm dealing with is an external application which synchronises with Navision items. When an item is inserted in this application, an identity column provides the primary key, which I need to capture in Navision. Both Navision and the external app have SQL 2000 backends.
Am I missing something or can I not do this?
draken
The following simplified code is trying to read an uncommitted record, from Navision 4, using ADO:
CREATE(adoConn); // Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Connection
CREATE(adoRS); // Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset
adoConn.IsolationLevel(256); // Set Uncommitted Read
adoConn.Open(_strConnString);
adoConn.BeginTrans;
adoConn.Execute('INSERT INTO Item (Name) VALUES ('Item Name')', intRecAffected); // intRecAffected returns 1 if the records was inserted
// ... and now for the troubled part...
adoRS := adoConn.Execute('SELECT [ID] FROM Item WHERE Name = 'Item Name'');
adoRS.MoveFirst;
intCount := adoRS.RecordCount; // Returns -1
adoConn.RollbackTrans;
// ... Close and Clean up
The item table I'm dealing with is an external application which synchronises with Navision items. When an item is inserted in this application, an identity column provides the primary key, which I need to capture in Navision. Both Navision and the external app have SQL 2000 backends.
Am I missing something or can I not do this?
draken
nosce te ipsum
0
Answers
-
Message deleted. Sorry.--
Josef Snayberk0 -
-
The problem is that I can not retrieve the record I inserted.
Put another way, in query analyzer I can do the following:BEGIN TRANSACTION INSERT INTO Item ([Name]) VALUES ('Item Name') SELECT [ID] FROM Item WHERE [Name] = 'Item Name' ROLLBACK TRANSACTION
The SELECT statement will return the ID of the just inserted record. When I try to do this in Navision through ADO automation, the select statement returns nothing.nosce te ipsum0 -
Have you tried to set the isolation level after opening the session or beginning the transaction?0
-
Thanks Kine, I've tried setting the isolation level pretty much anywhere in the code. no successnosce te ipsum0
-
Try this, probably this works:
INSERT INTO Item ([Name]) VALUES ('Item Name') SELECT @@IDENTITY As ItemId0 -
I found that even though adoRS.RecordCount returns -1, the following statement returns a value:
adoRS.Fields.Item(0).Value)
No doubt some subtlety just beyond my realm of perception. Anyway, problem no more, thanks for your input.
drakennosce te ipsum0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
