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
0
Answers
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.
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 :-)
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 :-)
ActiveSession.Reset();
ActiveSession.FindFirst();
Message('The database name is %1',ActiveSession."Database Name");
Note: Avoid doing a get like below, as I found this did not work 100% of the time. ActiveSession.Get(Database.ServiceInstanceId(), Database.SessionId())
When a backup of the production sql database gets restored on a separate database server with the same database name it's impossible to recognize that it is not the production database. So we decided to take the combination of database server name plus database name into account for determining that.