Sunday, April 26, 2015

Hot fix installation error

An error occurred in writing to the event log on machine DBSERVER: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
Error updating model database: Microsoft.Dynamics.Setup.AxSetupException: AxUtil call returned errors:The model contains a customization of a configuration key. The model cannot be imported because you can overlayer a configuration key from the patching layer only.

Solution:
Uninstall DMF for CU6 from Control panel / axutil

axutil delete /model:"Data Import Export Framework" from CMD .
Reinstall CU8



If you Need a Filter In a Form

//Add this to Class Declaration of a Form
public class FormRun extends ObjectRun
{
       QueryBuildRange rangeTenant;
       QueryBuildRange rangeAgreementId;
       QueryBuildRange rangeAgreementJournalId;
       QueryBuildRange rangeBuildingId;
       QueryBuildRange rangeRentTransId;
       QueryBuildRange rangePaymentDate;
       QueryBuildRange qbr,qbr1,qbr2,qbr3;
}
//Add this to Datasource Execute Query(Eg :- NetPaymentHistory_ds)
public void executeQuery()
{
      rangeTenant.value(TenantId.text() ? queryValue(TenantId.text()) 
              :SysQuery::valueUnlimited());
      rangeAgreementId.value(AgreementId.text() ? queryValue(AgreementId.text())
              : SysQuery::valueUnlimited());
      rangeAgreementJournalId.value(AgreementJournalId.text() ? queryValue(AgreementJournalId.text()) 
             : SysQuery::valueUnlimited());
      rangeBuildingId.value(BuildingId.text() ? queryValue(BuildingId.text())
            : SysQuery::valueUnlimited());
      rangeRentTransId.value(RentTransId.text() ? queryValue(RentTransId.text()) 
            : SysQuery::valueUnlimited());
      rangePaymentDate.value(PaymentDate.valueStr() ? queryValue(PaymentDate.valueStr())
            : SysQuery::valueUnlimited());
       super();
}
//Add this to Datasource init method (Eg :- NetPaymentHistory_ds)
public void init()
{
       super();
      this.query().dataSourceTable(tablenum(NetPaymentHistory)).clearDynalinks();
      rangeTenant = this.query().dataSourceTable(tablenum(NetPaymentHistory))
               .addRange(fieldnum(NetPaymentHistory, TenantId));
      rangeAgreementId = this.query().dataSourceTable(tablenum(NetPaymentHistory))
               .addRange(fieldnum(NetPaymentHistory, AgreementId));
      rangeAgreementJournalId = this.query().dataSourceTable(tablenum(NetPaymentHistory))
              .addRange(fieldnum(NetPaymentHistory, AgreementJournalID));
      rangeBuildingId = this.query().dataSourceTable(tablenum(NetPaymentHistory))
              .addRange(fieldnum(NetPaymentHistory, BuildingId));
      rangeRentTransId = this.query().dataSourceTable(tablenum(NetPaymentHistory))
             .addRange(fieldnum(NetPaymentHistory, RentTransId));
      rangePaymentDate = this.query().dataSourceTable(tablenum(NetPaymentHistory))
            .addRange(fieldnum(NetPaymentHistory, PaymentDate));
     // Enable caching of the document handling and note it display fields
    //purchRFQTable_ds.cacheAddMethod(tablemethodstr(PurchRFQTable, showDocHandIcon));
}
// Add this to Each of the String Control Field
public boolean modified()
{
     boolean ret;
    ret = super();
    NetPaymentHistory_ds.executeQuery();
    return ret;
}

Parent Form Refresh using x++

//Add this Method in Parent Form
void Form_doRefresh()
{
;
NetBuildings_ds.reread(); // Parent Form and Child Form Datasource Name
NetBuildings_ds.executeQuery();
NetBuildings_ds.refresh();
NetUnitDetails_ds.reread();
NetUnitDetails_ds.executeQuery();
NetUnitDetails_ds.refresh();
}
//Add this Method in Child Form where you need to Refresh the Parent Form
public void close()
{
    if(formHasMethod(element.args().caller(), identifierStr(Form_doRefresh)))//Form_doRefresh is Parent Method                                                                                                          Name
   {
        element.args().caller().Form_doRefresh();
   }
   super();
}
.................................................................................................................................................................
void bookrefresh()
{
   
.reread();

   
.refresh();

}
In the child form, you can do this –
void bookRefresh()
{
   FormRun callerForm = element.args().caller();
   if (callerForm)
   {
      if (callerForm.name() == formstr(
))

     {
         callerForm.bookRefresh();
     }
   }
}

Backup SQL DB using code

DECLARE @name VARCHAR(100) — database name 
DECLARE @path VARCHAR(256) — path for backup files 
DECLARE @fileName VARCHAR(256) — filename for backup 
DECLARE @fileDate VARCHAR(20) — used for file name
SET @path = ‘G:\BACKUP\11-09-2012_2300Hrs\’
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
DECLARE db_cursor CURSOR FOR 
SELECT name 
FROM master.dbo.sysdatabases 
WHERE name NOT IN (‘master’,’model’,’msdb’,’tempdb’)
OPEN db_cursor 
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0 
BEGIN 
SET @fileName = @path + @name + ‘_’ + @fileDate + ‘.BAK’ 
BACKUP DATABASE @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name 
END
CLOSE db_cursor
DEALLOCATE db_cursor

MANAGEMENT REPORTER ERROR

ERROR – UNABLE TO CONTACT THE SERVER, DO YOU WANT TO CHANGE THE SERVER SETTINGS (TEST CONNECTION)
SOLUTION –
Go to SQL SERVER MANAGEMENT STUDIO> SECURITY > LOGINS> NT AUTHORITY(CHECK WHICH LOGIN YOU HAVE GIVEN WHILE INSTALLING MR) > PROPERTIES>SERVER ROLES> CHECK BOX SHOULD BE ENABLED FOR Management reporter for that particular login – ASSIGN PUBLIC + SERVER ADMIN + SYSTEM ADMIN.

Convert WorkerId to UserId

userId = DirPersonUser::worker2UserId(MyHCMWorkerRecId);

How to Publish AX Reports for a specific AOS Instance

If you are running multiple instances of AX on a single environment, you have more than likely gone through the instructions as per this URL http://technet.microsoft.com/en-us/library/hh389760.aspx.
One of the steps identified in this URL talks about publishing reports using the following AX Powershell command: publish-axreports.
What isn’t perhaps obvious from the examples shown on the Deploy reports to the new Reporting Services Instance [AX 2012] page is – How do I publish reports for a specific AOS instance? (The examples shown is for the default instance)

When you look at the full syntax of the Publish-AxReports powershell command:


You will notice two optional parameters that are of interest, namely:
  • ServicesAOSName
  • ServicesAOSWSDLPort

These two parameters are used to “tell” the Publish-AXReports powershell command, which AOS to connect to when publishing reports.
The syntax used for these two parameters are as follow:
  • ServicesAOSName
This parameter contains the name of the server that runs the AOS instance that you want to connect to e.g. AXServer

  • ServicesAOSWSDLPort
This parameter contains the WSDL Port number that has been setup for your AOS instance e.g. 8102

Now that we understand the syntax, the Publish-AXReports command would look like this:

Publish-AXReport –ReportName * -id AXSSRS –servicesAOSname AXServer –servicesAOSWSDLPort 8102
Note – If you are running the Publish-AxReport command using the –servicesAOSName parameter you’ll also need to specify the –servicesAOSWSDLPort. They are both required to ensure that command executes correctly.

Calling an OData Service From a .NET Client


AX Service start error,

Error ---
SQL diagnostics: [Microsoft][SQL Native Client][SQL Server]Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.. Connect information was: Userid = [], Database = [CN_Dev1], Server = [MDT753], DSN = [], Other = []
Object Server 01: Server main session is being destroyed.
Object Server 01: Fatal SQL condition during login. Error message: "[Microsoft][SQL Native Client][SQL Server]Login failed for user 'NT AUTHORITY\NETWORK SERVICE'."
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. Reason: Failed to open the explicitly specified database. [CLIENT: ]

Resolution /Cause --
If it is a new database then check the user in security node, there must be some user that is missing from the list.Usually the users that syatem should add are network service & the machine-name$. If the users are not there, add these users in security node and in schema list.
While adding user in the user list, In new user window -> Securables page add two Stored procedures "CREATESERVERSESSIONS" & "CREATEUSERSESSIONS"  that is responsible for Server session and User Session. These can be found using search option and adding the two. Also provide execute permission on them. If this step is not taken then the AOS will not start.

Friday, April 24, 2015

To find total number of Column and Row in a DB


QUERY FOR FINDING NO OF COLUMN, NO OF ROWS IN EACH TABLE IN DB:

USE Dev_MicrosoftDynamicsAX
GO
CREATE TABLE #temp (
table_name sysname ,
row_count INT,
reserved_size VARCHAR(50),
data_size VARCHAR(50),
index_size VARCHAR(50),
unused_size VARCHAR(50))
SET NOCOUNT ON
INSERT #temp
EXEC sp_msforeachtable 'sp_spaceused ''?'''
SELECT a.table_name,
a.row_count,
COUNT(*) AS col_count,
a.data_size
FROM #temp a
INNER JOIN information_schema.columns b
ON a.table_name collate database_default
= b.table_name collate database_default
GROUP BY a.table_name, a.row_count, a.data_size
ORDER BY table_name asc,CAST(REPLACE(a.data_size, ' KB', '') AS integer) DESC
drop table #temp;

Delete a specific Batch Job

 The sql script to only delete a specific entry would be:

declare @BatchJobRecId bigint

select top 1 @BatchJobRecId = RECID from BATCHJOB
    where CAPTION = 'Workflow message processing' and
            COMPANY = 'dat'

delete from BATCHJOB where RECID = @BatchJobRecId

delete from BATCH where BATCHJOBID = @BatchJobRecId 


if (exists(select top 1 RECID from BATCHJOB where CAPTION = 'Data upgrade'))
begin
    print ''
    print 'There are still other btch jobs registered in AX with this name. Run again this script'
end


How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...