Options

How to get name of database server in AL w/o dll usage?

MarHanMarHan Member Posts: 33
Hi community,

is there a way to determine the name of the sql database server in AL without using dlls? I need the database name which I should get from the active session, but I have no clue how to get the database server name - the active session only carries the name of the BC server.

Thanks in advance and best regards

Markus

Answers

  • Options
    vaprogvaprog Member Posts: 1,118
    I don't know about AL on Azure, but from C/AL OnPremise I use Microsoft.Dynamics.Nav.Types.ServerUserSettings. Microsoft.Dynamics.Nav.Types.dll is part of any Dynamics NAV / BC installation. For development it needs to be placed somewhere in the path, or in the Add-ins folder. It then can be used with a standard installation without adding or modifying anything. No need to move the dll out from it's installation folder alongside the .exe.

    I use ServerName() for the SQL server name. I am not sure if this includes the instance or not, but I believe it does.

    I use DatabaseName.ToString for the database name on the above server.

    I have not found an other way that works. There are many suggestions about retrieving this data from the server .config file. I have not found any way of detecting your service instance and the path to that instance's configuration, so all those instructions only work with the default instance, and probably don't work on Azure at all.

    Try if this helps, and please report back, for the benefit of others.
  • Options
    MarHanMarHan Member Posts: 33
    Hi vaprog,

    this is a bit like we currently are doing it but we must get rid of this due to the universal code initiative where we're no longer allowed to use dlls even on-premises. A lot of stuff can already be done natively from AL but we didn't find a way for that yet. That's why I'm asking :-)
  • Options
    MarHanMarHan Member Posts: 33
    Or does anyone has a clever way to determine on-premises that the current system is a copy of the production database?

    We have a lot of customers that frequently create .bak backups from their production system via SQL to restore them as new test environments. The so created new test system must not behave like the production system (importing files, sending out emails, ...). Therefore we store and compare a token of a combination of database server name and database instance name with the current ones and recognize that database server and instance name has changed. If so, a lot of stuff gets disabled.

    I know that in Saas, there are events to regognize the creation of sandboxes for example. But we didn't find other ways to do it on-premises. Ideas welcome :-)
Sign In or Register to comment.