Saturday 26 December 2015

AX 2012 Retail - Schedule and Automate backups of SQL Server databases in SQL Server Express

Schedule and Automate backups of SQL Server databases in SQL Server Express


Dynamics AX Retail POS mostly uses SQL Server express per store database. SQL Express version is attractive because it provides a lot of value and free.  This is especially true for retailers that have many stores as the cost of database software licensing would quickly become cost prohibitive. The use of SQL Express requires careful planning and consideration for ongoing maintenance and an understanding of how the database will grow.

SQL Server Express editions do not offer a way to schedule either jobs or maintenance plans because the SQL Server Agent component is not included in these editions. Therefore, you have to take a different approach to back up your databases when you use these editions.

This article describes how to use a Transact-SQL script together with Windows Task Scheduler to automate backups of SQL Server Express databases on a scheduled basis

Follow these 3 steps to back up your SQL Server databases by using Windows Task Scheduler:

Step 1:

Use SQL Server Management Studio Express to create the following stored procedure in master database:

USE [master] 
GO 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
 
-- ============================================= 
-- Author: Microsoft 
-- Description: Backup Databases for SQLExpress
-- Parameter1: databaseName 
-- Parameter2: backupType F=full, D=differential, L=log
-- Parameter3: backup file location
-- =============================================
 
Create PROCEDURE [dbo].[sp_BackupDatabases]  
            @databaseName sysname = null,
            @backupType CHAR(1),
            @backupLocation nvarchar(200) 
AS 
 
       SET NOCOUNT ON; 
           
            DECLARE @DBs TABLE
            (
                  ID int IDENTITY PRIMARY KEY,
                  DBNAME nvarchar(500)
            )
           
             -- Pick out only databases which are online in case ALL databases are chosen to be backed up
             -- If specific database is chosen to be backed up only pick that out from @DBs
            INSERT INTO @DBs (DBNAME)
            SELECT Name FROM master.sys.databases
            where state=0
            AND name=@DatabaseName
            OR @DatabaseName IS NULL
            ORDER BY Name
           
            -- Filter out databases which do not need to backed up
            IF @backupType='F'
                  BEGIN
                  DELETE @DBs where DBNAME IN ('tempdb','ReportServer','ReportServerTempDB','master', 'model','msdb')
                  END
            ELSE IF @backupType='D'
                  BEGIN
                  DELETE @DBs where DBNAME IN ('tempdb','ReportServer','ReportServerTempDB', 'master', 'model','msdb')
                  END
            ELSE IF @backupType='L'
                  BEGIN
                  DELETE @DBs where DBNAME IN ('tempdb','ReportServer','ReportServerTempDB', 'master', 'model','msdb')
                  END
            ELSE
                  BEGIN
                  RETURN
                  END
           
            -- Declare variables
            DECLARE @BackupName varchar(100)
            DECLARE @BackupFile varchar(100)
            DECLARE @DBNAME varchar(300)
            DECLARE @sqlCommand NVARCHAR(1000) 
        DECLARE @dateTime NVARCHAR(20)
            DECLARE @Loop int                  
                       
            -- Loop through the databases one by one
            SELECT @Loop = min(ID) FROM @DBs
 
      WHILE @Loop IS NOT NULL
      BEGIN
 
-- Database Names have to be in [dbname] format since some have - or _ in their name
      SET @DBNAME = '['+(SELECT DBNAME FROM @DBs WHERE ID = @Loop)+']'
 
-- Set the current date and time n yyyyhhmmss format
      SET @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),101),'/','') + '_' +  REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','')  
 
-- Create backup filename in path\filename.extension format for full,diff and log backups
      IF @backupType = 'F'
            SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_FULL_'+ @dateTime+ '.BAK'
      ELSE IF @backupType = 'D'
            SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_DIFF_'+ @dateTime+ '.BAK'
      ELSE IF @backupType = 'L'
            SET @BackupFile = @backupLocation+REPLACE(REPLACE(@DBNAME, '[',''),']','')+ '_LOG_'+ @dateTime+ '.TRN'
 
-- Provide the backup a name for storing in the media
      IF @backupType = 'F'
            SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' full backup for '+ @dateTime
      IF @backupType = 'D'
            SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' differential backup for '+ @dateTime
      IF @backupType = 'L'
            SET @BackupName = REPLACE(REPLACE(@DBNAME,'[',''),']','') +' log backup for '+ @dateTime
 
-- Generate the dynamic SQL command to be executed
 
       IF @backupType = 'F' 
                  BEGIN
               SET @sqlCommand = 'BACKUP DATABASE ' +@DBNAME+  ' TO DISK = '''+@BackupFile+ ''' WITH INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'
                  END
       IF @backupType = 'D'
                  BEGIN
               SET @sqlCommand = 'BACKUP DATABASE ' +@DBNAME+  ' TO DISK = '''+@BackupFile+ ''' WITH DIFFERENTIAL, INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'        
                  END
       IF @backupType = 'L' 
                  BEGIN
               SET @sqlCommand = 'BACKUP LOG ' +@DBNAME+  ' TO DISK = '''+@BackupFile+ ''' WITH INIT, NAME= ''' +@BackupName+''', NOSKIP, NOFORMAT'        
                  END
 
-- Execute the generated SQL command
       EXEC(@sqlCommand)
 
-- Goto the next database
SELECT @Loop = min(ID) FROM @DBs where ID>@Loop
 
END

Step 2:

In a notepad, write the batch file code depending upon your scenario. The SQL ID used for backup should have at least the Backup Operator role in SQL Server.


Example: Full backups of all databases in the local named instance of SQLEXPRESS by using Windows Authentication

//File Name: Sqlbackup.bat 
//@backupType = 'F' : F means Full Backup
//If your instance is SQLEXPRESS use \SQLEXPRESS. If it is defaulut mention \ only
sqlcmd -S .\SQLEXPRESS -E -Q "EXEC sp_BackupDatabases @backupLocation='D:\SQLBackups\', @databaseName=’YOURDB’, @backupType='F'"

 
Similarly, you can make a differential backup of  YOURDB by pasting in 'D' for the @backupType parameter and a log backup of YOURDB by pasting in 'L' for the @backupType parameter.

Step 3:

Schedule a job by using Windows Task Scheduler to Run the batch file that we created earlier in step 2. To do this, follow these steps:

1. On the computer that is running SQL Server Express, click Start, Serach for Task Scheduler, and then click Task Scheduler. 

In the Task Scheduler click Create Task.


2. In General Tab, Type SQLBACKUP for the name of the task, Run whether user is logged in or not option.


3. In Trigger Tab then Click New, click Daily and Specify information for a schedule to run the task. (As recommend that you run this task at least one time every day.) Then slect enabled option, and then click Ok.



4. In Action Tab then click New, Click Browse, click the batch file that you created in step 2, and then click Ok.


5. Run the scheduled task at least one time to make sure that the backup is created successfully.



That's It!!!!

Make sure that there should be space on the drive to which the backups are being taken.


 Source: Microsoft

Monday 14 December 2015

What’s New in CU 10 for Microsoft Dynamics AX 2012 R3


What’s New in CU 10 for Microsoft Dynamics AX 2012 R3


This Article describes new or changed functionality, and updates, that were included in AX 2012 R3 cumulative update 10. Most changes were made in the Warehouse management, Transportation management, and Retail areas of Dynamics AX.

Warehouse management enhancements


  1. Improvements to replenishment 
    • Wave demand replenishment now recognizes existing min/max replenishment work as supply when evaluating if it should create new replenishment work. Cancelling wave based replenishment work will now unblock sales order work automatically. Demand replenishment will now consider all lines in the replenishment template even with different directive codes in situations where the entire demand quantity is not assigned to a put location. The directive code on work templates with the work order type Replenishment is now editable.
  2.  Improvements when viewing inventory on hand
    • A new field called Available physical on exact dimensions has been added to the On hand by location form. This field shows the available physical quantity for all the dimensions displayed on the screen. There have been performance improvements to the on hand stored procedure to use better query plans and make sure it is only called when necessary. A new clean up job has been added under Inventory management > Periodic > Clean up > Warehouse management on-hand entries cleanup. This job will delete records in the InventSum and WHSInventReserve tables for closed on-hand entries.
  3. Enhanced serial number functionalities
    • Items with a tracking dimension using serial numbers in the sales process can now be used with warehouse management processes. It is now possible to validate sales serials using the mobile device as well as the ability to indicate unreadable serial numbers. You can also enter sales serial numbers using the pack station and for sales order returns. Additionally, you can open the form that shows the recorded serial numbers from the Load lines tab on the Load details form. It is also possible to register serial numbers from the Picking list registration form, which will open the form for capturing sales serial numbers related to the sales line
    • In the manufacturing process, when consuming serialized components, it is now possible to postpone the registration of the serial number until production consumption. This will save time in warehouse processes as the serial will not be needed to be registered during receiving of serialized components.
  4. Improvements to inbound processes
    • The behavior of the mobile device menu item with the work creation process set to License plate receiving has changed. It will now only register the arrival of a purchase order and create put away work. It will leave the created work in an open state. If you want to use the old process, where the put away work was also conducted at that point in time, use a mobile device menu item with work creation process set to License plate receiving and put away. During the process of put away work using the mobile device, we have added several new options for exception handling for the warehouse worker. Three new buttons have been introduced during put away work; Split put, Override LP and Skip. They can be used to split items to multiple locations, consolidate items on a license plate at a location, or skip the current work line and proceed to the next put away line. Additionally, the Cancel button will now be available in all put away screens. 
    • During purchase receiving using the mobile device, the unit of measure will be defaulted to the UOM setup on the GTIN number. When using the Delivery schedule form on a purchase order line to split the delivery of a purchase order to different days, the load lines will also be updated. Performance when registering product receipt and querying for a put away location has been improved when using Volumetric and Stocking limits constraints for locations. Now the amount of full locations in the query should not affect performance. 
  5. Improvements to outbound processes
    • Over picking using the mobile device has been enabled during sales and transfer order picking work. Over picking will only be possible if there is enough inventory available at the current pick location and if it is not already allocated to other work. To enable over picking, both the work user and the mobile device must be set up to allow over picking. 
    • During picking on the mobile device, you can now use the Full button any time during picking to indicate that you cannot pick any more lines. It is now possible to block release to warehouse and creation of work for sales orders that exceeds customers credit limit. Performance of closing of containers during pack operations have been improved by avoiding some client/server calls. Performance when having containerization as part of wave posting been improved and optimized when scaling number of sales lines per order 
  6. Improvements to work templates
    • A new section of parameters has been added to the Work template form called Work header maximums. They can be used to split a work header when the sum of work lines exceeds the quantity specified.
  7. Integration to project and Integration to manufacturing


Transportation management enhancements 

  1. Create scheduled routes
    • Scheduled routes can now be generated from a route plan, where the segments of the scheduled route correspond to the hub configuration associated with the route plan. A batch job is used to create the scheduled routes depending on date range, particular days of the week and a load template. The scheduled routes can be used with Load building workbench in order to create optimal loads for the routes.
  2. Improvements to auto-release to warehouse process
    • hen using the auto-release to warehouse process it is now possible to consolidate multiple transfer orders based on To warehouse and From warehouse into the same shipment. 
  3. Integration to project 

Retail enhancements 

  1. Global refund tab on the Register form and the “Global refund check” report on the Retail store transactions and Online store transactions forms have been removed.
  2. Variant specific sales price is shown when a product variant is selected during product search or inventory lookup in POS. Previously the product base price was shown.
  3. This enhancement lets user select Infocode groups in open drawer store operation under AX functionality profile
  4. Retail POS SDK now allows for customization of the item types that are allowed for return.
  5. If the primary address on customer is marked as private address, the sales order created for a customer with this private address cannot be picked up at the retail store.
  6. Print Gift Receipts in Modern point of sale (MPOS): Added gift receipt feature at MPOS for: 
    • Sales Transactions 
    • Show journal, both Gift receipt preview and print  
  7. The changes in the hotfix enable look up of another store's customers using real-time service.
  8. Introduced alternative algorithm for calculating discounts, which is enforced if predefined max number of calculations steps/loops is exceeded. In this case, point of sale will switch to the marginal value algorithm, which does not guarantee the best discount but provides much better performance characteristics. This feature is configurable in Retail Parameters
  9. Enable Extended Login registration in MPOS, This operation provides an interface that you can use to enroll or remove workers in extended logon using peripherals. Supported peripherals include barcode scanners and magnetic strip readers
  10. Retail MPOS installation was not supported on the Windows 10 Long Term Service Branch. With this hotfix we have added this support extending the supported operating systems for MPOS to the following: 
    • Windows 8.1 Update 1- Server 2012 R2 Update 1 
    • Windows 10- Windows 10 Long Term Service Branch



Source: https://mbs.microsoft.com/files/public/CS/AX2012R3/WhatsNew_MicrosoftDynamicsAX2012-R3-CU10.pdf


Friday 4 December 2015

SSRS Deployment Failed - The "DeployToReportsServerTask" task failed unexpectedly


Error # 1:

The "DeployToReportsServerTask" task failed unexpectedly.
System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)
   at Microsoft.Dynamics.Framework.Deployment.Reports.DeployToReportsServerTask.Deploy(IEnumerable`1 transitiveReferenceClosure, DeploymentLogger logger, Boolean restartReportServer)
   at Microsoft.Dynamics.Framework.Deployment.Reports.DomainBoundHelper.Deploy(IEnumerable`1 transitiveReferenceClosure, DeploymentLogger logger, Boolean restartReportServer)
   at Microsoft.Dynamics.Framework.Deployment.Reports.DomainBoundHelper.Deploy(IEnumerable`1 transitiveReferenceClosure, DeploymentLogger logger, Boolean restartReportServer)
   at Microsoft.Dynamics.Framework.Deployment.Reports.DeployToReportsServerTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() C:\Program Files (x86)\MSBuild\Microsoft\DynamicsTools\Microsoft.Dynamics.Framework.Design.Reporting.Modeling.targets 466 6 VendorDetailsReport


Error # 2: An error occurred : Access is denied.

If User Account Control (UAC) is enabled on the machine, close the application, right-click the application, and then click Run as administrator. C:\Program Files (x86)\MSBuild\Microsoft\DynamicsTools\Microsoft.Dynamics.Framework.Design.Reporting.Modeling.targets 466 6 VendorDetailsReport

Error # 3: The deployment was aborted. You do not have privileges to deploy to server: SINGU-VIRTUAL. For deployment, you must have administrative rights to the SQL Server Reporting Services (SSRS) server. Contact your administrator to deploy. C:\Program Files (x86)\MSBuild\Microsoft\DynamicsTools\Microsoft.Dynamics.Framework.Design.Reporting.Modeling.targets 466 6 VendorDetailsReport


Solution:

Open Visual Studio with "Run As Administrator" and open the project. Try to re-deploy the solution again