Sunday, 3 August 2014

AX2012: Error when downgrading the AX server kernel Object Server 01: Fatal SQL condition during login. Error message: "The internal time zone version number stored in the database is higher than the version supported by the kernel (5/2). Use a newer Microsoft Dynamics AX kernel."

Description: It can happen that you need to downgrade the AOS kernel in a system. Depending on the build you are going back to, you might get an error message.
Error message:

Object Server 01:  Fatal SQL condition during
login. Error message: "The internal time zone version number stored in the
database is higher than the version supported by the kernel (4/1). Use a newer
Microsoft Dynamics AX kernel."

Solution:

You need to change the value for the column value SYSTIMEZONESVERSION in the table SQLSystemVariables. If you look in
the event viewer you can see that it finds the value 4, but expected 1 (4/1).
So the solution is to change the value to 1.

Get sql statement form the select statement ax 2012 R2

static void SR_getSQLStatement(Args _args)
{
    CustTable custTable;
    CustTrans custTrans;
    ;
    select generateonly firstOnly AccountNum, CustGroup from custTable
                           join custTrans where custTrans.AccountNum == custTable.AccountNum;
    info(custTable.getSQLStatement());
}
public void executeQuery()
{
   Query q;
   QueryBuildDataSource qbds;
   ;
   q = this.query();
   qbds = q.dataSourceName("PurchTable"); //Replace with the       current Table
   info( qbds.toString() );
   super();
}

Request for the permission in ax 2012 R2

InteropPermission permission;
try
{
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
    // Get the CLR error before any other CLR operation
   errorMessage = AifUtil::getClrErrorMessage();
   CodeAccessPermission::revertAssert();
   throw error(errorMessage);
}
or
Error: “Request for the permission of type ‘InteropPermission’ failed.”

Many times we would like to call method from dot net assemblies (or) com so we have to assign permission to execute the code .below are ways can be used for CLR and COM

Assign permissions to execute the code (CLR Interop). Like this:

InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);
;
permission.assert();

Assign permissions to execute the code (COM object). Like this::

InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
;
permission.assert();

Microsoft SQL Shedule Backup

Step 1: Open Object explorer in SQL and select “Management” ---> Maintenance Plans
Step 2: Create a new maintenance plan for Shedule Backup
Step 3: A new window pops up and asking for the name of the plan.
Step 4: Once entered, another new window opens
Step 5:  On the Top Left corner (Marked by red color box), from the Maintenance Plan Tasks, select “Back up Database Task”.?
Step 6: Drag and drop “Back up Database Task” to Design part
Step 7:  Double click the Box and a window opens as follows:
Step 8: Select the Database to be taken back up
Step 9: Select the folder where the database has to be taken back up  and also enter the frequency when the database back up has to take place.

Disable UAC on Windows 2012 R2

cmd-> (Regedit)

You have the option to turn off UAC via registry by changing the DWORD “EnableLUA” from 1 to 0 in “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system”.
(or)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system /v EnableLUA /t REG_DWORD  /d 0 /f

You will get a notification that a reboot is required. After the reboot, UAC is disabled.

https://community.dynamics.com/ax/b/yetanotherdynamicsaxblog/archive/2014/01/09/disable-uac-on-windows-2012-r2.aspx
http://www.mahmoudthoughts.com/2013/12/disable-user-account-control-in-windows.html

AOS takes a long time to start in Ax 2012 R2

Problem:
When you start an AOS, you may notice it takes a very long time before the service gets the status “Started”. A possible cause is left-over data in SysClientSession table. When starting up, the AOS seems to check if the client is still around.  The SysClientSessions contains the data for the client sessions that are currently active in the system.

Solution:
1. Shut down AOS for sing instance or all AOSes for multiple instances (not an ideal way in Production)
2. Use SQL Server Management Studio and run this sql
SELECT        SESSIONID, SERVERID, VERSION, LOGINDATETIME, LOGINDATETIMETZID, STATUS, USERID, SID, USERLANGUAGE, HELPLANGUAGE, CLIENTTYPE,
SESSIONTYPE, CLIENTCOMPUTER, DATAPARTITION, RECVERSION, RECID
FROM            SYSCLIENTSESSIONS

DELETE  FROM SYSCLIENTSESSIONS;
3. Delete all client records
4. Restart AOS(es)

Tuesday, 22 July 2014

Read Text File in ax 2009

static void ReadTextFile(Args _args)
{
TextIo file;
FileName filename = @"c:\temp\cars.txt";
CarTable carTable;
container con;
FileIoPermission permission;
#File
;
try
{
// Create the permission class
permission = new FileIoPermission(filename, #io_read);
// Ask for permission to write the file
permission.assert();
// Create the TextIo object
file = new TextIo(filename, #io_read);
if (!file)
throw Exception::Error;
// Note that we now use inDelimiters
// instead of outDelimiters as in the
// previous example
file.inRecordDelimiter(#delimiterCRLF);
file.inFieldDelimiter(";");
// Write the header info
info("CarId - CarBrand - Mileage - Model - ModelYear");
// Read the first record from the file
con = file.read();
// Loop as long as the file status is ok
while (file.status() == IO_Status::Ok)
{
// Write the content to the infolog
info(strfmt("%1 - %2 - %3 - %4 - %5",
conpeek(con,1),
conpeek(con,2),
conpeek(con,3),
conpeek(con,4),
conpeek(con,5)));
// Read the next record from the file
con = file.read();
}
}
catch(Exception::Error)
{
error("You do not have access to write the file to the
selected folder");
}
// Revert the access privileges
CodeAccessPermission::revertAssert();
}