Executing script (command against external database) after AX Entity export - axapta

I'm working on a project to create an external data warehouse using some data from Microsoft Dynamics AX 7. I am using the new BYOD approach which allows you to define an external database, and then use that database as the target when exporting one or more Dynamics entities.
See: https://blogs.msdn.microsoft.com/dynamicsaxbi/2016/07/27/export-dynamics-ax7-entities-to-your-own-azure-sql-database/
At the time of writing, this export mechanism is able to do incremental exports (only inserted or updated records) but it lacks support for record deletions.
With AX7 you cannot directly access the AX database from external systems, so what I'm wanting to do is run a post-export SQL script that will examine the MSSQL Change Tracking tables and based on that data for deleted rows, execute a series of delete systems on the same external database.
If it is possible, I'm hoping to use this more generic, sql-centric approach rather than getting involved in writing custom AX entities and export code.
How might one best approach this?

Related

Copying Business Setup Data to a new instance

Re: AX 2012 R2 Service Pack 2
I am looking for options in copying Business Setup data (eg Companies, Chart of Accounts, Location, etc) from one AX instance to another instance. The instances are currently in development so we don't have to worry about wiping out data. As of now one single instance has a master copy of all Business Setup information. What I want to do is copy that data to multiple development instances.
I can refresh the Model Store and Business Data with no problem. But the Business Setup data is a different beast entirely. In AX 2009, there was a feature to copy this information, but it has since been removed in AX 2012. I've read multiple articles on this but each one warns that it's either not recommended or only for testing. I need something that is safe to use.
Has anyone found a clean process to copy business setups from one instance to another in AX 2012?
The really simple solution is to have an AX setup database/environment without any transactions.
To deploy do a SQL Server, do a backup of the setup database and restore to the target database followed by a full AX dictionary synchronize in the target application.
This will of cause wipe out any transactions, setup etc. done in the target database.
After import a script is run to change file locations not to point to setup locations etc.
You may need to save some data beforehand using the Administration, Periodic, Data Export/Import, Export then import after the wipe.
Below is the actual procedure used by one of my customers. The setup is done in the production environment and the target may be the flow testing environment.
Sketch list:
Backup setup
Export target data
Stop target AOS
Restore to target
Run SQL script
Start target AOS
Database synchronization
Run AX script
Import target data
This procedure is also great for making a test environment of a production environment.
There is a Microsoft document, "Microsoft Dynamics AX 2012: Tech Domain New Features Module 5: Moving Between Environments" on this subject (Google that entire title and it will be the first hit).
The procedure that Jan outlines in his answer is correct but more high level. There is data in several tables that store configuration information that you want to wipe out after the restore, and insert the rows that were there prior to the restore. I.e., there are some tables that you need to export before you do the restore, so that you can create SQL scripts to insert that data.
You can do it without these procedures, but then you have a messy environment with AOS servers listed that aren't in the environment, and if you have a reporting server, help server, etc., you have to go through and change all of that manually. If you save the data prior to the restore, then you have scripts that will get the configuration where it needs to be and it just takes one second.
You can copy commonly used values from an existing company to a new one, as long as both companies are in the same database. For example, if you have a standard list of symptom codes that is common to all your service management implementations, you can copy the codes easily from one company to another.
To copy data to a new company using RapidStart Services:
Open the new company.
Choose the Lightbulb that opens the Tell Me feature icon, enter Configuration Worksheet, and then choose the related link.
Choose the Copy Data from Company.
On the Copy Company Data page, choose a company to copy from in the Copy From field, and then choose the OK button.
Select a table from one of the configuration packages that you have imported, and then choose the Copy Data action.
This works for me with Microsoft

oracle export and import datapump

I have a quick question on oracle datapump. I have a small oracle database 11gR2 which contains different schemas (more than 8).I want to move this database to a new server and i am trying to use impdp/expdp method. I did a full export of the database under system user. THe new server also runs 11gR2.
Now if create a new database with same tablespaces on the new server, can i use a full import. Is this the recommended way to do it?
I know i can do it schema wise, but however it would require me creating the roles, and other supporting objects first and also identifying which schemas actually have objects on them.
I don't think there's such a thing as a "recommended" way to do it. You might as well ask what's the "recommended" data to put in an Oracle database. It kind of depends what your needs are.
The only problem that I've had with using a "full" import/export in the past, is that the export then also includes SYSTEM (and other default Oracle schemas) which you don't really want overwriting your new database. (Actually, this used to cause me some problems with the old imp/exp command -- but theoretically it would be the same problem with Data Pump).
Fortunately, Data Pump allows you to exclude certain objects from your export. When I do full exports, I tend to exclude all the schemas that are already created in the new database, at db-creation time. Include the following in your parameter file:
EXCLUDE=SCHEMA:" IN ('SYS','SYSTEM','WMSYS','OUTLN','MGMT_VIEW','XDB','ANONYMOUS','SYSMAN','ORDSYS','ORDSYS','ORDPLUGINS','SI_INFORMTN_SCHEMA','MDSYS','EXFSYS','DBSNMP','DMSYS','CTXSYS','DIP','TSMSYS','ORACLE_OCM')"

linq to entities 3.5 across multiple databases in same engine

What do i need to do in order to be able to query across multiple databases which are in the same db engine?
I have added the .edmx file of 1 database, but i only need 1 view from another db.
Thanks in advance!
Here are a couple of options:
Depending on your database platform, make the view from your second database available in your first database. If you're using SQL Server, you can use a linked server. If you're using Oracle, you can use a DB Link. Simply create a view in your main database where the view's select statement utilizes the linked server or db link to reference the view from your second db.
Create a second .edmx file for your second database. This is the route I chose recently. However I was dealing with one SQL Server DB and one was Oracle DB. There were also multiple tables and functions from both being used. I determined that it was cleaner in my case to create two separate data access projects, one for each DB, each with it's own .edmx.
Hope this helps.

Updating SQL Server database with SQL scripts

I have a number of manually written scripts (.sql) for tables, views and stored procedures that are used from an ASP.NET application. These scripts drop the object and recreates them. I need a way to update the database when the scripts change without deleting the object. For example, when a column is added to an existing table that has rows in it, I would need to update this table with this extra column without losing the rows.
I need a way to "update" the database on a single click (I can hook up the changes using a batch file). Does Visual Studio support this kind of functionality?
If you get Visual Studio Team System - Database Edition 2008 - which is now bundled with "Developer Edition" for free - it handles that. Visual Studio database projects without that edition really just store the static SQL that you want to track. The Database Edition is capable of determining the 'deltas' between your SQL and what's in a target database, generating that script, and executing against your database. You do get the option of reviewing that generated SQL, but by default it is very safe [it won't run if it thinks that there will be any data lost].
Yes - it's called Database Projects.
You can define a Visual Studio Database Projects, have create and change SQL scripts inside it, and then execute those against a database connection of your choice when you need to.
See this blog post here for a great explanation, or read the whole series that the 4 guys from Rolla wrote.

How to create a database and populate it during setup

I would like to find a way to create and populate a database during asp.net setup.
So, what I'm willing to do is:
Create the database during the setup
Populate the database with some initial data (country codes or something like that)
Create the appropriate connection string in the configuration file
I'm using .NET 3.5 and Visual Studio 2005, and the Database is SQL Server 2005.
Thanks in advance.
If you are creating an installer I'm sure there is a way to do it in there, but I am not all that familiar with that.
Otherwise, what you might do is the following.
Add a application_start handler in the Global.asax, check for valid connection string, if it doesn't exist, continue to step two.
Login to the server using a default connection string
Execute the needed scripts to create the database and objects needed.
Update the web.config with the connection information
The key here is determining what the "default" connection string is. Possibly a second configuration value.
Generally, you'll need to have SQL scripts to do this. I tend to do this anyway, as it makes maintaining and versioning the database much easier in the long run.
The core idea is, upon running the setup program, you'll have a custom action to execute this script. The user executing your setup will need permissions to:
Create a database
Create tables and other database-level objects in the newly-created database
Populate data
Your scripts will take care of all of that, though. You'll have a CREATE DATABASE command, the appropriate CREATE SCHEMA, CREATE TABLE, CREATE VIEW, etc. commands, and then after the schema is built, the appropriate INSERT statements to populate the data.
I normally break this into multiple scripts, but YMMV:
Create schema script
"Common scripts" (one for the equivalent of aspnet_regsql for web projects, one with the creation of the Enterprise Library logging tables and procs)
Create stored procedure script, if necessary (to be executed after the schema's created)
Populate initial data script
For future maintenance, I create upgrade scripts where a single script typically handles the entire upgrade process.
When writing the scripts, be sure to use the appropriate safety checks (IF EXISTS, etc) before creating objects. And I tend to make mine transactional, as well.
Good luck!
Well, actually I found a tutorial on MSDN: Walkthrough: Using a Custom Action to Create a Database at Installation
I'll use that and see how it goes, thanks for your help guys, I'll let you know how it goes.
If you can use Linq to Sql then this is easy.
Just import your entire database into the Linq to Sql designer. This will create objects that describe all objects in your database, including the System.Data.Linq.DataContext derived class that encapsulate the entire database setup.
Now you can call DataContext.CreateDatabase() to create the database.
See here more information.

Resources