Tag Archives: SQL

[AX2012] Get list of security roles with name


To get export the security roles along with the AOT name of the security will need you to either write something in X++ or go into SQL

I went the SQL route and this is my code:

select
S.AOTNAME, L.Text as AOTNAME, LD.Text as DESCRIPTION
from SECURITYROLE S
Left outer join ModelElementLabel L
on L.Module = SUBSTRING(S.Name, 2, 3)
and L.LabelId = SUBSTRING(S.Name, 5, 7)
and L.Language = 'en_us'
Left outer join ModelElementLabel LD
on LD.Module = SUBSTRING(S.DESCRIPTION, 2, 3)
and LD.LabelId = SUBSTRING(S.DESCRIPTION, 5, 10)
and LD.Language = 'en_us'

This will give a list of the AOT names and the Label name and Description

[AX2012] Compare objects between models


SQL Makes everything better

When ever adding a new hot-fix or a new model from another source we need to compare the code touch points between that and existing code.

Ax makes that easy using the compare layers tool, however that only compares layers

So the other way is to go code upgrade and use those tools which may or may not work depending on your case (for example you put a 3rd part model and want to compare what var or cus or usr layer code you need to change)

This brings to writing x++ code or so in yummy SQL

Requirements:

  1. Know what models have changed

  2. Know what models will be affected / need to be compared

Know what models have changed

You know what hotfixes have been put in and there may be more than one. so note the numbers of the hotfixes or models that were added. Use the Get-AxModel command to get the models Ids for them

Know what models will be affected / need to be compared

You will probably need to know all the Models Id’s from the higher layers. So if you have a hotfix that you added then take a note of all model id’s that are a part of isv, isp, var, vap, cus, cup, usr, usp …. you know what i mean

The Fun begins with SQL

select et.ElementTypeName, et.TreeNodeName, med1.ParentHandle, med1.ElementHandle, me.* from ModelElementData med1
join ModelElement me
on ((me.ElementHandle = med1.ParentHandle and med1.ParentHandle <> 0)
or (med1.ParentHandle = 0 and me.ElementHandle = med1.ElementHandle))
join ElementTypes et
on et.ElementType = me.ElementType

where med1.ModelId in (<model ids changed in csv>)
and med1.ElementHandle in (select medisv.ElementHandle from ModelElementData medisv
where medisv.ModelId in (<model ids affected in csv>))
order by me.ElementType

That gives us a result set with main element type and the path to it.

Hopefully this gives an easier way to figure out what has changed and reduces your time. If this post does help you let me know, I am planning to invest in a query to further give more details about each element.

Alter gear SQL index management


Update 06 April 2010: A new version has been released which saves the connection strings

After 3 hours, and a few other gruelling hours of trying to the get UI working Alter gear Sql index manager is now Alive.

Here is how to run it:

Step 1: Start the application:

1

Step 2 (optional) : select the Filter (Average fragmentation %)

2

Step 3 : Select database to tune

4

Step 4: Choose indexes to Reorganise / Defrag

5

Click “Defragment selected”

image

Defrag calls Reorganise, and Rebuild the Rebuild method on the index.

Happy re-indexing

Database index defragmenter


I recently came across a best practise which said – do not defragment all indexes in an SQL database. A few reasons apart fro the obvious of it being a costly transaction. Are there any tools that will let me analyse the indexes and i can choose which ones to defragment? I have started creating an application to do this which will soon be hosted on Codeplex, and yet again under the “Alter gear” project name.

Can’t connect to remote sql server/express?


Got a few links that can help.
Make sure that you check the log file in the server’s directory, to find the nature of the error.

this blog gives a brief description of the protocol errors:
http://blogs.msdn.com/sql_protocols/archive/2006/02/21/536201.aspx

if you are not able to connect to the server, follow the steps given in
http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx

And if your client is Vista, turn off the firewall.. that will solve the issue, Im trying to find how to enable the firewall and still connect to the DB.

Will update accordingly,
Goood luck