Showing posts with label LCS. Show all posts
Showing posts with label LCS. Show all posts

LCS Deploy-able Package merging


LCS Deploy-able Package merging 


Sometimes times we need to Apply multiple packages on Production especially when we are applying Both Application hotfixes and Binaries (Deploy-able packages).


There is a simple way to merge multiple deployable packages into a single package.

Step-1 Navigate to Assets library then click on the deployable package.
Step-2 Select multiple packages and click on merge.


Step-3 A Pop will appear like the below image, Enter package name and description.


Step-4 Click on confirm button. The package will appear in deployable with the name you entered.


Step-5 Navigate to environment click on maintain and apply combine hot fixes.



VM Development server using LCS


VM Development server using LCS


Microsoft Azure using Microsoft Dynamics Lifecycle Services (LCS). This topic applies to deploying a development environment on Dynamics 365 for Finance and Operations


Let's Begin

Use this procedure to deploy a development environment on Azure using LCS.
Open your LCS project and click on the Hamburger icon of LCS Menu Bar and click on cloud hosted environment. 



Once the page is loaded then click on Add button to start the environment provision process.




Select Environment Type



There are two types of topology available on LCS, Demo, and DEVTEST.
In Our Demo, we select DEVTEST Topology.



In the very next step, you will find two options Build and Test and Develop Machine.

Build and Test

Select this option when you want to provide the environment for the Build machine.
There are only a few steps difference between both environments is only the configuration steps of build agent and TFS.

Important 

Microsoft highly recommends to don't use Build & Test for development purpose.


DETEST


This topology uses only for development purposes..

If you faced the below error, means the Azure ARM connector not define on your LCS.





Click on the hamburger icon again and go to the project set to add Azure connector.



Now select the Azure connector Tab and click on Add button, check the below screenshot.



Fill the required fields 

  • Name 
  • Azure Subscription 
  • Azure Tenant Domain

Please check the below screenshot.



If you don't know your Azure Subscription Id then login to Azure Portal with Admin accounts, you also have the rights of Administrator on Azure AD.



Search Subscription in the search bar or you can find the path with the help of the below screenshot.


Click on Add and follow the MS ARM on-boarding blog. 



After completion of Onboarding ARM. GO to project setting Add Azure Connector and fill the required fields and click Next.

If your ARM Onboarding process is successfully completed a role will be shown to you. if this role is not showing to you then click on the Azure portal and follow the ARM instructions again.

If everything is showing as expected then click on next.




Click next Again and select your Azure region and click connect.


After completion of the Azure connector, Click on the hamburger Icon and click on cloud-hosted environment again.


Then follow the steps I mentioned at the start of the project. once you come on the below screen Enter the Environment Name.



for Advance configuration setting for Environment click on Advance settings.. below information will be shown to you. 



Select the configuration as per your requirement and click on close


Select the Machine Size and click on Next to finalize the provision. It will take 5 to 6 working hours in the environment configuration. 

I personally prefer the D4V2 Machine for development you can change as per your requirement.

Feel free to contact me if you are facing issues in the implementation of the above blog.






Azure App Registration


Azure App Registration



Any application that wants to use the capabilities of Azure AD must first be registered in an Azure AD tenant. This registration process involves giving Azure AD details about your application, such as the URL where it’s located, the URL to send replies after a user is authenticated, the URI that identifies the app, and so on.

To register a new application using the Azure portal
1.       Sign in to the Azure portal.
2.       If your account gives you access to more than one, click your account in the top right corner, and set your portal session to the desired Azure AD tenant.
In the left-hand navigation pane, click the Azure Active Directory service, Click App registrations
and click New application registration.





Following are the apps I have already registered as per my requirement.


In the Azure portal, we have two types of Apps

·         Web API

Select "Web app / API" for client applications and resource/API applications that are installed on a secure server. This setting is used for OAuth confidential web clients and public user-agent-based clients. The same application can also expose both a client and resource/API.

·         Native Apps

Select "Native" for client applications that are installed locally on a device. This setting is used for OAuth public native clients.

Register your App by clicking New Application Registration Button. A popup window like below will be visible and Fill the required items and select the application type as per your requirement.


The application will visible like the below screenshot after creating the process completely.




Now click on Application for detail. Please check the below screenshot.


 Application Owner

Add only if you want to make someone an owner. Otherwise, skip the steps.

 Application Permission

Below is the permission which is required to activate.






Following are the further detail of each permission. Please check the below screenshot.








Keys


For Web API we need a secret key with the help of this key client will get the Authentication.

After generation of the key, please save the key because it will not visible again to you.




Copy D365FO Azure SQL Database to a SQL


Copy a Finance and Operations database from Azure SQL Database to a SQL Server environment

Overview

To move a database, you use the sqlpackage.exe command-line tool to export the database from Azure SQL Database and then import it into Microsoft SQL Server 2016. Because the file name extension for the exported data is .bacpac, this process is often referred to as the bacpac process.
The high-level process for a database move includes the following phases:
1.     Create a duplicate of the source database.
2.     Download the latest SSMS  Link the version number should be greater than Release number: 17.7
3.     Run a SQL script to prepare the database.
4.     Export the database from the Azure SQL database.
5.     Import the database into SQL Server 2016.
6.     Run a SQL script to update the database.

Before you begin

Stop the following services
·         Microsoft batch server
·         Data import/ Export Service
·         IIS services

Now Create a Copy of the source database with the help of below script.
CREATE DATABASE AxDB_XXX AS COPY OF axdb_mySourceDatabaseToCopy
This SQL statement runs asynchronously. In other words, although it appears to be completed after one minute, it actually continues to run in the background. For more information, see CREATE DATABASE (Azure SQL Database). To monitor the progress of the copy operation, run the following query against the MASTER database in the same instance.
SELECT * FROM sys.dm_database_copies

After compilation of copy database remove the extra schemas if they are there
·         SHADOW
·         BACKUP
Above mentioned schema need to remove from your newly copy database.




After the above action removes some users manually the script provided by Microsoft will not remove them even throw an error while deleting. So you have to remove them manually.





After this execute the below script which is available in MS docs.Microsoft.com
--Prepare a database in Azure SQL Database for export to SQL Server.
--Disable change tracking on tables where it is enabled.
declare
@SQL varchar(1000)
set quoted_identifier off
declare changeTrackingCursor CURSOR for
select 'ALTER TABLE ' + t.name + ' DISABLE CHANGE_TRACKING'
from sys.change_tracking_tables c, sys.tables t
where t.object_id = c.object_id
OPEN changeTrackingCursor
FETCH changeTrackingCursor into @SQL
WHILE @@Fetch_Status = 0
BEGIN
exec(@SQL)
FETCH changeTrackingCursor into @SQL
END
CLOSE changeTrackingCursor
DEALLOCATE changeTrackingCursor

--Disable change tracking on the database itself.
ALTER DATABASE
-- SET THE NAME OF YOUR DATABASE BELOW
MyNewCopy
set CHANGE_TRACKING = OFF
--Remove the database level users from the database
--these will be recreated after importing in SQL Server.
declare
@userSQL varchar(1000)
set quoted_identifier off
declare userCursor CURSOR for
select 'DROP USER ' + name
from sys.sysusers
where issqlrole = 0 and hasdbaccess = 1 and name <> 'dbo'
OPEN userCursor
FETCH userCursor into @userSQL
WHILE @@Fetch_Status = 0
BEGIN
exec(@userSQL)
FETCH userCursor into @userSQL
END
CLOSE userCursor
DEALLOCATE userCursor
--Delete the SYSSQLRESOURCESTATSVIEW view as it has an Azure-specific definition in it.
--We will run db synch later to recreate the correct view for SQL Server.
if(1=(select 1 from sys.views where name = 'SYSSQLRESOURCESTATSVIEW'))
DROP VIEW SYSSQLRESOURCESTATSVIEW
--Next, set system parameters ready for being a SQL Server Database.
update sysglobalconfiguration
set value = 'SQLSERVER'
where name = 'BACKENDDB'
update sysglobalconfiguration
set value = 0
where name = 'TEMPTABLEINAXDB'
--Clean up the batch server configuration, server sessions, and printers from the previous environment.
TRUNCATE TABLE SYSSERVERCONFIG
TRUNCATE TABLE SYSSERVERSESSIONS
TRUNCATE TABLE SYSCORPNETPRINTERS
--Remove records which could lead to accidentally sending an email externally.
UPDATE SysEmailParameters
SET SMTPRELAYSERVERNAME = ''
GO
UPDATE LogisticsElectronicAddress
SET LOCATOR = ''
WHERE Locator LIKE '%@%'
GO
TRUNCATE TABLE PrintMgmtSettings
TRUNCATE TABLE PrintMgmtDocInstance
--Set any waiting, executing, ready, or canceling batches to withhold.
UPDATE BatchJob
SET STATUS = 0
WHERE STATUS IN (1,2,5,7)
GO
-- Clear encrypted hardware profile merchand properties
update dbo.RETAILHARDWAREPROFILE set SECUREMERCHANTPROPERTIES = null where SECUREMERCHANTPROPERTIES is not null

Export the database

Open a Command Prompt window and run the following commands.
cd C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin

SqlPackage.exe /a:export /ssn:<server>.database.windows.net /sdn:<database to export> /tf:D:\Exportedbacpac\my.bacpac /p:CommandTimeout=1200 /p:VerifyFullTextDocumentTypesSupported=false /sp:<SQL password> /su:<sql user>
Here is an explanation of the parameters:
·         ssn (source server name) – The name of the Azure SQL Database server to export from.
·         sdn (source database name) – The name of the database to export.
·         tf (target file) – The path and name of the file to export to.
·         sp (source password) – The SQL password for the source SQL Server.
·         su (source user) – The SQL user name for the source SQL Server. We recommend that you use the sqladmin user. This user is created on every Finance and Operations SQL instance during deployment. You can retrieve the password for this user from your project in Microsoft Dynamics Lifecycle Services (LCS).



Screen shot of exporting database


After compilation of Export of the database upload over LCS and download on the target Machine where you need to import the database.




Import the database

When you import the database, we recommend that you follow these guidelines:
·         Retain a copy of the existing AxDB database, so that you can revert to it later if you must.
·         Import the new database under a new name, such as AxDB_XXX.
To help guarantee the best performance, copy the *.bacpac file to the local computer that you're importing from. Open a Command Prompt window and run the following commands.

Use the following script to import database
cd C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin
SqlPackage.exe /a:import /sf:D:\Exportedbacpac\my.bacpac /tsn:localhost /tdn:<target database name> /p:CommandTimeout=1200

Here is an explanation of the parameters:
·         tsn (target server name) – The name of the SQL Server to import into.
·         tdn (target database name) – The name of the database to import into. The database should not already exist.
·         sf (source file) – The path and name of the file to import from.
For me Script look like…
SqlPackage.exe /a:import /sf:C:\backup\AxDB.bacpac /tsn:localhost /tdn:AxDBUAT /p:CommandTimeout=1200
Screen shot of import database







Update the database

Run the following SQL script against the imported database. This script adds back the users that you deleted from the source database and correctly links them to the SQL logins for this SQL instance. The script also turns change tracking back on. Remember to edit the final ALTER DATABASE statement so that it uses the name of your database.

CREATE USER axdeployuser FROM LOGIN axdeployuser
EXEC sp_addrolemember 'db_owner', 'axdeployuser'
CREATE USER axdbadmin FROM LOGIN axdbadmin
EXEC sp_addrolemember 'db_owner', 'axdbadmin'
CREATE USER axmrruntimeuser FROM LOGIN axmrruntimeuser
EXEC sp_addrolemember 'db_datareader', 'axmrruntimeuser'
EXEC sp_addrolemember 'db_datawriter', 'axmrruntimeuser'
CREATE USER axretaildatasyncuser FROM LOGIN axretaildatasyncuser
EXEC sp_addrolemember 'DataSyncUsersRole', 'axretaildatasyncuser'
CREATE USER axretailruntimeuser FROM LOGIN axretailruntimeuser
EXEC sp_addrolemember 'UsersRole', 'axretailruntimeuser'
EXEC sp_addrolemember 'ReportUsersRole', 'axretailruntimeuser'
CREATE USER axdeployextuser FROM LOGIN axdeployextuser
EXEC sp_addrolemember 'DeployExtensibilityRole', 'axdeployextuser'
CREATE USER [NT AUTHORITY\NETWORK SERVICE] FROM LOGIN [NT AUTHORITY\NETWORK SERVICE]
EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE'


UPDATE T1 SET T1.storageproviderid = 0    , T1.accessinformation = ''
    , T1.modifiedby = 'Admin'    , T1.modifieddatetime = getdate()
FROM docuvalue T1
WHERE T1.storageproviderid = 1 --Azure storage

ALTER DATABASE [<your AX database name>] SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 6 DAYS, AUTO_CLEANUP = ON)
GO
DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking
DROP PROCEDURE IF EXISTS SP_ConfigureTablesForChangeTracking_V2
GO
-- Begin Refresh Retail FullText Catalogs
DECLARE @RFTXNAME NVARCHAR(MAX);
DECLARE @RFTXSQL NVARCHAR(MAX);
DECLARE retail_ftx CURSOR FOR
SELECT OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id) fullname FROM SYS.FULLTEXT_INDEXES
      WHERE FULLTEXT_CATALOG_ID = (SELECT TOP 1 FULLTEXT_CATALOG_ID FROM SYS.FULLTEXT_CATALOGS WHERE NAME = 'COMMERCEFULLTEXTCATALOG');
OPEN retail_ftx;
FETCH NEXT FROM retail_ftx INTO @RFTXNAME;

BEGIN TRY
      WHILE @@FETCH_STATUS = 0 
      BEGIN 
            PRINT 'Refreshing Full Text Index ' + @RFTXNAME;
            EXEC SP_FULLTEXT_TABLE @RFTXNAME, 'activate';
            SET @RFTXSQL = 'ALTER FULLTEXT INDEX ON ' + @RFTXNAME + ' START FULL POPULATION';
            EXEC SP_EXECUTESQL @RFTXSQL;
            FETCH NEXT FROM retail_ftx INTO @RFTXNAME;
      END
END TRY
BEGIN CATCH
      PRINT error_message()
END CATCH

CLOSE retail_ftx; 
DEALLOCATE retail_ftx;
-- End Refresh Retail FullText Catalogs


Enable change tracking

If change tracking was enabled in the source database, ensure to enable change tracking again in the newly provisioned database in the target environment using the ALTER DATABASE command.
To ensure the current version of the store procedure (related to change tracking) is used in the new database, you must enable/disable change tracking for a data entity in data management. This can be done on any entity as this is needed to trigger the refresh of store procedure.

Re-provision the target environment

When copying a database between environments, you will need to run the environment re-provisioning tool before the copied database is fully functional, to ensure that all Retail components are up-to-date.

Follow these steps to run the Environment reprovisioning tool.
1.    In the Shared asset library, select Software deployable package.
2.    Download the Environment reprovisioning tool.
3.    In the asset library for your project, select Software deployable package.
4.    Select New to create a new package.
5.    Enter a name and description for the package. You can use Environment reprovisioning tool as the package name.
6.    Upload the package that you downloaded earlier.
7.    On the Environment the details page for your target environment, select Maintain > Apply updates.
8.    Select the Environment a reprovisioning tool that you uploaded earlier, and then select Apply to apply the package.
9.    Monitor the progress of the package deployment.

Start to use the new database

To switch the environment and use the new database, first stop the following services:
·         World Wide Web Publishing Service
·         Microsoft Dynamics 365 Unified Operations: Batch Management Service
·         Management Reporter 2012 Process Service
After the services have been stopped, rename the AxDB database AxDB_orig, rename your newly imported database AxDB, and then restart the three services.
To switch back to the original database, reverse this process. In other words, stop the services, rename the databases, and then restart the services.




Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...