Logo - allcomputers.us
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Server

Configuring a SQL Server database for Microsoft Dynamics NAV & Writing less expensive C/AL code for customizations

7/29/2011 11:22:17 AM

Configuring a SQL Server database for Microsoft Dynamics NAV

It is imperative that while configuring Microsoft Dynamics NAV, the hardware and software recommendations from Microsoft are taken into consideration. From using the latest version of Microsoft Windows, Microsoft SQL Server, or other Microsoft stack products that are intended to be used with Dynamics NAV or the hardware/server sizing, it is important that the Microsoft guidelines for these are taken into account.

Let's discuss some of the parameters and features that are to be properly set at the time of setting up the Dynamics NAV database on the SQL Server.

Defining database and transaction log files

While defining the Database Files and Transaction Log Files of the Dynamics NAV SQL server database, it is strongly recommended to store the two sets on two separate physical drives. This not only helps greatly in improved performance of the database, but is also a key feature of a better disaster recovery management plan.

In order to avoid manually increasing the size of the database files every time it reaches the brink, we could check the Unrestricted Growth option for the database and log files. This can also be achieved by using the ALTER DATABASE T-SQL command on the SQL Server after the database has been created. The only disadvantage is that, this feature of unrestricted growth uses a lot of system resources and we will have to monitor the disk size for the database and log files.

Defining rules using collations

Collations are used to define the rules for a particular language, character set, or region. In SQL Server, the collation can be defined at various levels. The various objects of an SQL Server instance inherit the collation type from instance, though that can be changed later on for each database, column, variable, or parameter. In the Microsoft Dynamics NAV SQL Server database option, collation can be specified under the Collation tab while creating the database or by using the Alter Database option under the Collation tab.

Binary is case sensitive and is the fastest sort order. However, it cannot be used concurrently with Case-sensitive and Accent-sensitive options.

Writing less expensive C/AL code for customizations

There are a few considerations to keep in mind while writing a customized C/ AL code, as poorly written code can affect the performance of the application or a business process significantly.

Retrieving data using FINDFIRST/FINDLAST/FINDSET

Using FINDFIRST instead of the following FIND('-') statement is also an inexpensive command to retrieve the first record from the recordset.

The following is the code for retrieving the first record using the FIND statement:

GLEntry.SETRANGE(...);
IF NOT GLEntry.FIND('-') THEN
MESSAGE('No entries in the GL Entry table');

The previous code can be replaced with the following code:

GLEntry.SETRANGE(...);
IF NOT GLEntry.FINDFIRST THEN
MESSAGE('No entries in the GL Entry table');

Using FINDLAST instead of the following FIND('+') is an inexpensive way to retrieve the last record from the recordset.

The following is the code for retrieving the last record using the FIND('+') statement:

GLEntry.SETRANGE(...);
IF GLEntry.FIND('+') THEN
MESSAGE('Last entry no. used -'+ GLEntry."Entry No.");

The previous code can be replaced with the following code:

GLEntry.SETRANGE(...);
IF GLEntry.FINDLAST THEN
MESSAGE('Last entry no. used -'+ GLEntry."Entry No.");

FINDFIRST and FINDLAST should not be used with the REPEAT UNTIL or NEXT command, as these two commands do not create a cursor to the next record, which is needed in the loop.


Instead of using the loop statements with FIND('-') command, use the inexpensive statement FINDSET to find the subset of records in the recordset.

The following is the code for retrieving the subset of records using the FIND('-') statement:

IF GLEntry.FIND('-') THEN
REPEATUNTIL GLEntry.NEXT = 0;

The previous code can be replaced with the following code:

IF GLEntry.FINDSET THEN
REPEAT UNTIL GLEntry.NEXT = 0;

Using the NEXT statement

The use of the NEXT statement inadequately could be the source of the biggest performance glitches. The interpretation of NEXT by SQL has to be explicitly defined if a NEXT is used without finding a subset, with FINDFIRST or FINDLAST, or is used after a changed key/filter.

Using ISEmpty

Instead of using IF Recordset.FIND('-') THEN using IF Recordset.ISEMPTY THEN is more efficient and less taxing on the server resources.

Locking the recordset

While programming on the Dynamics NAV for SQL Server option, it is a good practice to use LOCKTABLE and lock the recordset before modifying any records. This ensures that the uncommitted dataset that is read from SQL Server is locked and cannot be modified by another user.

Locking occurs when the following sequence of events takes place:

  1. 1. User X reads a record without using locktable.

  2. 2. User Y reads the same record without locks.

  3. 3. User Y modifies the record.

  4. 4. User X gets the error message Another user has modified the record for this tablename after you retrieved it from the database.

If both users X and Y in the previous example use explicit locks before fetching the record, they are blocked and will have to wait, until one or the other releases the lock.

Deadlocks can occur if both the users are blocking each other and both of them are waiting for either one of them to release the lock or resources.


Let's take a look at the following example:

  1. 1. User X locks the customer, vendor table.

  2. 2. User Y locks the customer, vendor table.

  3. 3. User X gets the customer 10000 and User Y gets vendor 10000.

  4. 4. User X tries to get vendor 10000, User Y tries to get customer 10000.

  5. 5. User X gets a deadlock warning, while user Y is able to get the desired record. SQL Server randomly decides which user can get the record.

To avoid the previously mentioned conditions, we'll use the following guidelines at least whenever possible:

  • Don't use "message" statements or any other user input mechanism after the table has been locked.

  • Perform validations prior to the locking of table.

Disabling the "find-as-you-type" feature

The "find-as-you-type" feature in Dynamics NAV takes a heavy toll on performance, as with every keystroke, the SQL query is done.
 
Other -----------------
- Microsoft Dynamics NAV : Expanding the database
- SharePoint 2010 Search : Search Reporting (part 2)
- SharePoint 2010 Search : Search Reporting (part 1) - Farm Level Reports & Site Collection Reports
- SharePoint 2010 Search : Relevancy Algorithms
- Microsoft Dynamics CRM 2011 : Using Mail Merge to Generate a Word Document That Includes List Member Information
- Microsoft Dynamics CRM 2011 : Creating Opportunities from List Members
- Microsoft Dynamics CRM 2011 : Copying Members to Another Marketing List
- BizTalk 2009 : How to Tune Each Subsystem (part 2)
- BizTalk 2009 : How to Tune Each Subsystem (part 1) - ASP.NET, SOAP, and HTTP
- Microsoft PowerPoint 2010 : Organizing Clips
- Microsoft PowerPoint 2010 : Managing Pictures
- Microsoft PowerPoint 2010 : Accessing Commands Not in the Ribbon & Customizing the Way You Create Objects
- Microsoft Dynamics AX 2009 : The MorphX Tools - Code Compiler & Dynamics AX SDK
- Microsoft Dynamics AX 2009 : The MorphX Tools - Visual Form Designer and Visual Report Design
- Windows Server 2008 R2 : Work with Windows Updates (part 3) - Use Group Policy to Configure Automatic Updates
- Windows Server 2008 R2 : Work with Windows Updates (part 2)
- Windows Server 2008 R2 : Work with Windows Updates (part 1)
- SQL Server 2005 : Privilege Escalation Without Ownership Chains
- SQL Server 2005 : Privilege and Authorization - Ownership Chaining
- SQL Server 2005 : Privilege and Authorization - Basic Impersonation Using EXECUTE AS
 
 
Most view of day
- Visual Basic 2010 : Objects Serialization (part 2) - Soap Serialization & Providing Serialization for Custom Objects
- Windows Server 2008 R2 : Initial Configuration Tasks
- Exchange Server 2010 : Setting Up Public Folders (part 1) - Creating Public Folders & Configuring Public Folder Permissions
- Deploying with Windows DS : Capturing Custom Images & Using Windows DS with BDD 2007
- Removing Malware from Windows Vista (part 1) - Understanding Common Malware Issues
- Windows Phone 7 : Using Media Player to Shuffle Songs in Your Media Library
- SharePoint 2010 : Securing Information - Securing Sites
- Windows Server 2008 R2 : Designing a Group Policy Infrastructure
- SharePoint 2010 PerformancePoint Services : Creating Dashboards in the Browser
- SQL SErver 2008 R2 : Parallel Query Processing
Top 10
- Adobe InDesign CS5 : Managing Pages and Books - Navigating Pages & Adding Color Labels to Pages
- Adobe InDesign CS5 : Managing Pages and Books - Changing the Page Size
- Dreamweaver CS5 : Understanding Server Behaviors & Applying and Managing Server Behaviors
- Dreamweaver CS5 : Packaging Your AIR Application
- SQL Server 2008 : Physical server design - Disk configuration (part 2) - Validating disk storage performance and integrity
- SQL Server 2008 : Physical server design - Disk configuration (part 1) - Creating and aligning partitions
- Using Microsoft Content Management Server to Display SharePoint Content (part 3)
- Using Microsoft Content Management Server to Display SharePoint Content (part 2) - Limitations of the MCMS Connector for SharePoint
- Using Microsoft Content Management Server to Display SharePoint Content (part 1) - The MCMS Connector for SharePoint Technologies
- Microsoft Excel 2010 : Changing Summary Calculations, Showing and Hiding Data Items, Sorting Your Pivot Table
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone