NAV Code and SQL Procedure in same transaction

SonGoten13
Member Posts: 44
Hi all,
1. Do some NAV code that inserts some data
2. Call a stored sql procedure with automation that should have access to the data from 1.
There should be NO commit between 1 and 2 because when a error occurs it should roll back the hole thing.
Is it possible to access uncommitted data in an sql procedure?
SQL Server 2008, NAV 2009 R2 Classic Client
greetings
1. Do some NAV code that inserts some data
2. Call a stored sql procedure with automation that should have access to the data from 1.
There should be NO commit between 1 and 2 because when a error occurs it should roll back the hole thing.
Is it possible to access uncommitted data in an sql procedure?
SQL Server 2008, NAV 2009 R2 Classic Client
greetings
0
Answers
-
As long as nav is not delay inserting the records (bulk insert) and you stored procedure is reading uncommitted data.0
-
You should add the (WITH NOLOCK) hint to your stored procedure.0
-
thanks for the fast responses
@ara3n
- i dond't really know what you mean by "bulk insert"; how can i check if thats the case?; in my concreate example here, NAV is posting a sales shipment
- how can i tell my sql procedure to do that? i tried around with "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" but with no success
@Mark
- you mean CREATE PROCEDURE [dbo].[CoolProcedureName] @param1 varchar(20) WITH NOLOCK AS [...] ? That brings a compile error "unknown option". Otherwise i don't know where to put that "hint"0 -
Keep in mind that the external call to SQL is its own transaction. So you have to be careful of when it is called. Consider the following:
1. Make some changes in NAV
2. Make some changes in SQL
Here, everything would get rolled back regardless for where the error happens. But now consider this.
1. Make some changes in NAV
2. Make some changes in SQL
3. More changes in NAV
If an error occurs in step 3, only the changes in NAV get rolled back. The SQL changes will be committed.There are no bugs - only undocumented features.0 -
@bbrown: thanks for the info; would be no problem in my example, cause i commit it anyway after the sql code
Well, i broke the whole thing down to a small insert in nav and select in sql example, and there it works when i use "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED".
So not a general problem. However in my real life scenario it doesn't work. Anyone an idea wich parameters could influence that behaviour?
@Edit: Found a solution. A modify/get/find in NAV from that record i want to select in SQL made it work. Makes no sense to me, as there are no changes to that rec in NAV after an insert, that happens before, but well, it does the job.0 -
thats the nav delayed insert (bulk insert feature)0
-
ah ok, good to know, thx.
Is this always enabled or is it controllable?0 -
always enabled. you have to call a modify for nav to actually write to db0
-
There are some situations were NAV won't bulk insert e.g. when the table has a RecordID field or a BLOB field. One thing you can do if you don't want to bulk insert is to use an IF e.g. ...
IF INSERT THEN ;
...this will also not bulk insert. Of course if you need it to error if the insert fails then you could do...
IF NOT INSERT THEN ERROR(InsertFailedText);0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions