Monday, December 10, 2012

How to kill idle users from NAV server

There are instances where you may be asked to find an easy method for removing the idle users from the NAV database. There has been a well known method where you write a NAV report object to check the idle time of each user and delete the session id by checking their idle time. Then you schedule the NAV report through Navision Application server (NAS).

However, this is an alternative method; in this way, you write a SQL script and schedule it through SQL Job, in the same way you schedule your maintenance plans in your SQL Server such as making daily backups, truncating log files etc.

SQL Script :
USE MyDatabase
 DECLARE @EXECSQL varchar(max)
 SET @EXECSQL = ''select @EXECSQL = @EXECSQL+ 'Kill ' + Convert(varchar, [Connection ID]) + ';'
 From Session WHERE [Application Name]='Microsoft Dynamics NAV Classic client' and [Idle Time]>3000
 EXEC(@EXECSQL)

How to schedule the above SQL Script:
Just enable a job. It’s a matter of pasting the code and give the date & time etc. This is similar to Windows scheduler as well.

Steps for scheduling via a SQL Job:
1.        Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select 'New Job'

2.        In the 'New Job' window enter the name of the job and a description on the 'General' tab.

3.       Select 'Steps' on the left hand side of the window and click 'New' at the bottom.

4.       In the 'Steps' window enter a step name and select the database you want the query to run against.

5.       Paste in the T-SQL command you want to run into the Command window and click 'OK'.

6.       Click on the 'Schedule' menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).

7.       Click 'OK' - and that’s done!!


Special Note: I just thought of posting this into the blog even for own future references. Thanks very much Isuru (Isuru Dias) for letting this to me.

Wednesday, August 29, 2012

REPEATABLEREAD Isolation Level in SQL Server


When you have issues around the table blockings etc, one of the solutions may be to change the database transaction isolation level from ‘SERIALIZABLE transaction isolation level” to “REPEATABLE READ transaction isolation level” This will improve general performance in situations where multiple users are experiencing blocking when they are entering journal entries, sales order entries, purchase order entries and similar tasks.
The following example would give you an idea about the different impacts
Statement 1:
CUSTOMER.LOCKTABLE;
CUSTOMER.SETCURRENTKEY("Document No.", "Line No.");
CUSTOMER.SETRANGE(CUSTOMER."Document No.", '1');
CUSTOMER.SETRANGE(CUSTOMER."Line No.", 1, 10);
IF CUSTOMER.FIND('-') THEN
REPEAT
UNTIL (CUSTOMER.NEXT()=0);

Statement 2:
IF CUSTOMER.FIND('-') THEN
REPEAT
UNTIL (CUSTOMER.NEXT()=0);

With SERIALIZABLE transaction isolation level, all existing records will be locked during the first "REPEAT UNTIL" loop and other users will also be blocked from inserting new records within the specified range. The record that has Document No=2, Line No=1 will also be blocked. This will be main draw back in ‘SERIALIZABLE transaction isolation level”. In other words, the second loop will always read exactly the same result as the first loop.
With REPEATABLE READ transaction isolation level, however there is a potential where someone can theoretically insert a new record within the mentioned range which will then appear as an additional record in the second loop.

You can configure Ms Dynamics NAV to use the REPEATABLEREAD isolation level in SQL Server, by running the following TSQL statement against the SQL database; this will disable the 4194304 flag

update [$ndo$dbproperty] set diagnostics = diagnostics | 4194304

Source : http://blogs.msdn.com/b/nav/archive/2011/05/12/microsoft-dynamics-nav-changes-by-version.aspx

Saturday, December 10, 2011

How to shrink a Navision DB Log file in a SQL 2008 Server

alter database "Demo Database NAV (6-0)" set recovery simple
go

checkpoint
go

alter database "Demo Database NAV (6-0)" set recovery full
go


dbcc shrinkfile ("Demo Database NAV (6-0)_Log" , 1)
go

Monday, November 7, 2011

Navision Code Coverage

The Code Coverage tool differs from the debugger tool that is included in Microsoft Navision. However, the Code Coverage tool contains the same limitations as the debugger tool. You require Granule 7110 (Report & Dataport Designer) to run the Code Coverage tool.

Note If you cannot perform the following procedure, contact your local certified developer partner for help.

To determine the objects and the code that are used during a function, such as posting a sales order, follow these steps:

Step 1:Create a sales order, but do not post it.
Step 2:On the Tools menu, click Debugger, and then click Code Coverage.
Step 3:In the Code Coverage window, click Start.
Step 4:Return to the Sales Order window, and then post the sales order that you created in
step 1.

Step 5:Return to the Code Coverage window, and then click Stop.

Step 6:You see a list of all the objects that were used when the sales order was posted.
On the Tools menu, click Object Designer.
Step 7:Click Codeunit, click Codeunit 1 (ApplicationManagement), and then click Code to open the Code Overview window.

Codeunit 1 (ApplicationManagement) is one of the code units that are listed in the Code Coverage window.

The lines of code that have been run appear as black text. The lines of code that have not been run appear as red text.
In the Code Overview window, the lines of code appear just like the lines of code that appear in the debugger tool. For example, the Code Overview window uses the following formatting:
Bullets appear on each line that contains executable code.
The lines that are marked with a bullet are the only lines in which the information that is displayed is correct.
The lines of code that are not marked with a bullet appear in the same colors as the adjacent lines of code.

To clear the lines that are displayed in the Code Coverage window, click Start. To stop the Code Coverage routine, click Stop.

Note When you run the Code Coverage tool, a large log file may be generated. To reduce the size of the log file, perform steps 1 to 6, and then click Start in the Code Coverage window. After the Code Coverage tool starts, perform step 7.

Sunday, November 6, 2011

How to use CAST function in the definition of Linked Tables in NAV

Example 1

The original SQL script for the Linked Table

USE [NavisionTEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[Cronus$UC_CustomTableName]
AS
SELECT DeviceId,
(SELECT DATEADD(hour,
(SELECT DATEDIFF(hour, GETDATE(), getutcdate()) AS EXPR1), CustomTableName.ScanTime) AS EXPR1) AS ScanTime, DisplayLine1
FROM [2ndDATABASE].pfo.dbo.metric_CustomTableName AS CustomTableName
WHERE (DisplayLine1 LIKE '%toner%') OR
(DisplayLine1 LIKE '%cartridge%') ;



Example 2

The same SQL script used to define the Linked Table, being modified with the CAST function

USE [NavisionTEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[Cronus$UC_CustomTableName]
AS
SELECT DeviceId,
(SELECT DATEADD(hour,
(SELECT DATEDIFF(hour, GETDATE(), getutcdate()) AS EXPR1), CustomTableName.ScanTime) AS EXPR1) AS ScanTime,
CAST(DisplayLine1 AS NVARCHAR(250)) AS DisplayLine1
FROM 2ndDATABASE.pfo.dbo.metric_CustomTableName AS CustomTableName
WHERE (DisplayLine1 LIKE '%toner%') OR
(DisplayLine1 LIKE '%cartridge%')

Sunday, May 8, 2011

How to set up NAV 2009 SP1 and NAV 2009 R2 in the same server

It is possible to setup both NAV 2009 SP1 and NAV 2009 R2 in a single server. If you have already setup a NAV 2009 SP1 server and you are in need of setting up the NAV 2009 R2 server also in the same server (without uninstalling the NAV 2009 SP1), you could do it by following the below steps.

STEP 1: Do not un-install your existing NAV 2009 SP1 server installation. Instead, copy the following folders from you installation CD to your Program Files folder;

- Classic
- Role Tailored Client

It is obvious that you cannot make the folder names as ‘Classic’ and ‘Role Tailored Client’ as they are already available in the Program Files folder for running NAV 2009 SP1. Therefore, create them as ‘Classic R2’ or ‘Role Tailored Client R2’ as shown here.




STEP 1: Do not un-install your existing NAV 2009 SP1 server installation. Instead, copy the following folders from you installation CD to your Program Files folder;

STEP 2: Now it is time to create a service for NAV 2009 R2 – for the NAV Service Tier Application. You may be able to create a service by using below commands. To run this, you will have to use the command prompt of Windows.

To create a NAV Service;
SC CREATE "MicrosoftDynamicsNAVServer$R2" binpath= "C:\Program Files\Microsoft Dynamics NAV\60\Service R2\Microsoft.Dynamics.Nav.Server.exe" start= auto DisplayName= "Microsoft Dynamics NAV Server R2"

To Delete Service:
SC DELETE "MicrosoftDynamicsNAVServer$R2"

To create a NAV Web Service;
SC CREATE "MicrosoftDynamicsNAVWS$SrvR2" binpath= "C:\Program Files (x86)\Microsoft Dynamics NAV\60\Service R2\Microsoft.Dynamics.Nav.Server.exe $SrvR2" start= auto obj= "NT Authority\NetworkService" DisplayName= "NAV2009R2 Web Services" type= share
netsh http add urlacl url=http://+:7049/DynamicsNAVR2 user="NT Authority\NetworkService"

STEP3: Once the above step is carried out, you may need to manually register some of the new DLL file only available with R2 version. This could be done by using the ‘regasm’ command on your console.
For example, for registering the DLL, Microsoft.Navision.Mail.dll, you can use the command as follows;

C:\windows\microsoft.net\framework\v2.0.50727\regasm /codebase /tlb:Microsoft.Navision.Mail.tlb Microsoft.Navision.Mail.dll
STEP4: Once you see that you can compile all objects in the database, you could start accessing R2 Client. One of the best practices among the options would be creating a separate shortcut for the R2 Client.

The above exercise may be very useful, when your users are in need of testing /checking the new features of the NAV 2009 R2 version. May be you are in a situation where you need users to see the new features of NAV 2009 R2. May be you are in need of users to check the system after upgrading from NAV 2009 SP1 to R2. Regardless of the intention, this will work for you!

Thursday, April 28, 2011

How Do I Manually Register Type Libraries, DLLs / ActiveX Controls, and ActiveX Servers?

The following commands may be needed in the case of installing multiple NAV Service Tiers in single Server. For example, when you are in need of installing NAV 2009 SP1 and NAV 2009 R2 in the same server, the second instance needs to be installed and registered in the Windows Registry using below commands

Problem:
How do I manually register type libraries (.tlb), ActiveX controls (.ocx), and ActiveX servers

Solution:

Type Libraries
Type libraries are binary files that contain all type information needed to utilize procedures and classes in a DLL. To register a type library, you can use regtlib.exe as follows:
1. Select Start » Run.
2. Type the following in the dialog box that appears:
C:\WINDOWS\system32\URTTemp\regtlib.exe
Where is the location of your type library file.

ActiveX Controls

ActiveX controls are files with a .ocx extension. These controls come in 16-bit as well as 32-bit forms, with 32-bit being the most predominant. To register an ActiveX control, you can use regsvr32.exe as follows:

1. Select Start » Run.
2. Type the following in the dialog box that appears:

regsvr32 This could also be a OCX file

Where is the location of your ActiveX control.

If you have a 16-bit control, you can run regsvr instead of regsvr32. If your ActiveX control is registered incorrectly, you must first unregister it and then register it again. In both cases, you will get a dialog box prompting you that your control has been unregistered or registered successfully. To unregister a control, use the switch /u (i.e., regsvr32 /u ).

Note: For a complete listing of the switches available, just type regsvr32 from the Start » Run dialog box.

ActiveX Servers

ActiveX servers can be in the form of both DLLs and executables (EXEs). DLLs can be registered similar to an ActiveX control (e.g., regsvr32 C:\Teststand\BIN\TEAPI.DLL). However, when registering an EXE, you must use the switch /RegServer as follows:
1. Select Start » Run.
2. Type the following in the dialog box that appears:
/RegServer

Where is the location of your EXE server (e.g., C:\TestStand\Bin\REngine.exe /RegServer).

In the same manner, to unregister an EXE ActiveX Server use the switch /UnRegServer (e.g., C:\TestStand\Bin\REngine.exe /UnRegServer). RegServer and UnRegServer are switches whose functionality is built into the executable.

Note: If you find that you are dealing extensively with Type Libraries, ActiveX Controls, and ActiveX Servers, you may find the utility linked below useful. It is a very simple utility that allows you to quickly register and unregister Type Libraries, ActiveX Controls, and ActiveX Servers. The application is distributed freely by the Common Controls Replacement Project (CCRP), and the readme file included with the application explains how to use it. Also refer to KB 2XDAB1SJ for more inofrmation about .ocx files.

You may also try below commands in the case of an eror in the above commands for registering required DLL files,

Examples:

c:\Windows\system32>
gacutil/i "C:\Program Files (x86)\Common Files\Microsoft Dynamics NAV\Dynamics Online Payment Client\Microsoft.Dynamics.NAV.DO.ClientProxyWrapper.dll"

C:\windows\microsoft.net\framework\v4.0.30319\regasm /codebase /tlb:Microsoft.Navision.Mail.tlb Microsoft.Navision.Mail.dll

c:\windows\microsoft.net\framework\v2.0.50727\regasm /unregister /tlb:microsoft.navision.mail.tlb microsoft.navision.mail.dll

C:\windows\microsoft.net\framework\v2.0.50727\regasm /codebase /tlb:Microsoft.Navision.Mail.tlb Microsoft.Navision.Mail.dll

Business Central SaaS Extension Design: Implementing Plant Tracking with AL Event Subscribers

  Extending Business Central SaaS: Plant Tracking Using AL Extensions  1️⃣ Problem Statement In many manufacturing and service-oriented or...