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

MarHan
Member Posts: 34
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
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 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.0 -
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 :-)
0 -
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 :-)0 -
Try this.
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())0 -
As already mentioned, this gives me only the name of the sql database but not the name of the sql database server.
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.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions