How to get servername in RTC

reijermolenaar
Member Posts: 256
Hi all,
Does anybody know how to retrieve the name of the SQL server in the RTC?
Both CONTEXTURL and virtual table "2000000047 - Server" are not available...
Does anybody know how to retrieve the name of the SQL server in the RTC?
Both CONTEXTURL and virtual table "2000000047 - Server" are not available...
Reijer Molenaar
Object Manager
Object Manager
0
Answers
-
I don't know if there is an easy way. But the following solution would work.
Create(MSDOM);
MSDOM.load(APPLICATIONPATH+ 'CustomSettings.config');
MSNode := MSDOM.SelectSingleNode('// Location of DatabaseServer key');
Message(MSNode.Value);0 -
Thanks Rashed!
It works indeed: \:D/IF ISSERVICETIER THEN BEGIN IF ISCLEAR(DomDoc) THEN CREATE(DomDoc); DomDoc.load(APPLICATIONPATH + 'CustomSettings.config'); DomNode := DomDoc.selectSingleNode('//appSettings/add[@key=''DatabaseServer'']'); ExitValue := DomNode.attributes.item(1).text; CLEAR(DomDoc); END ELSE BEGIN AllObj.SETRANGE("Object Type", AllObj."Object Type"::Table); AllObj.SETRANGE("Object ID", 2000000047); IF AllObj.FINDFIRST THEN BEGIN // SQL RecRef.OPEN(2000000047); FldRef := RecRef.FIELD(2); FldRef.SETRANGE(TRUE); RecRef.FINDFIRST; FldRef := RecRef.FIELD(1); ExitValue := FORMAT(FldRef.VALUE); RecRef.CLOSE; END; END;
Reijer Molenaar
Object Manager0 -
Thanks a lot - just what I needed today. I would have spent a couple of hours (at least) figuring it out otherwise.Alastair Farrugia0
-
You are welcome. Although reijermolenaar provided the full solution. So thanks reijermolenaar for fully working solution.
All I did was guide him to the right path.0 -
Hi
I am still having a problem with this.
The posted solution only works if the application server is on the same server as the SQL.
In a 3 teir environment I still cannot determine the applcation server.
Any ideas anyone?0 -
try and debug the service tier.0
-
The original question was about the SQL Server.
If you want the middle tier, you could try replacing "DatabaseServer" with "ServerInstance".
If you want the full server name, e.g. MiddleMachine:7046/DynamicsNAV, then I wouldn't know how to get that, but there must be some way of getting that, as you can see it (and change it) in RTC.Alastair Farrugia0 -
To get the full server name port and instance name:
Name DataType Subtype Length DomDoc Automation 'Microsoft XML, v3.0'.DOMDocument DomNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode WSHNetwork Automation 'Windows Script Host Object Model'.WshNetwork
GetServerAndServiceName(VAR _ServerTxt : Text[30];VAR _PortTxt : Text[30];VAR _ServiceTxt : Text[30]) IF ISCLEAR(WSHNetwork) THEN CREATE(WSHNetwork); IF ISCLEAR(DomDoc) THEN CREATE(DomDoc); _ServerTxt := WSHNetwork.ComputerName(); DomDoc.load(APPLICATIONPATH + 'CustomSettings.config'); DomNode := DomDoc.selectSingleNode('//appSettings/add[@key=''ServerPort'']'); IF NOT ISCLEAR(DomNode) THEN _PortTxt := DomNode.attributes.item(1).text; // Server Port DomNode := DomDoc.selectSingleNode('//appSettings/add[@key=''ServerInstance'']'); IF NOT ISCLEAR(DomNode) THEN _ServiceTxt := DomNode.attributes.item(1).text; // Server Name CLEAR(DomDoc); Clear(WSHNetwork);
0 -
Brilliant..
Thanks deV.ch
WSHNetwork.Computername was just what I needed.
:P0 -
Anybody got this to work in Nav 2015?
I get "You can create a Automation Object .. on Microsoft Dynamics Nav Server. You must create it on a client computer.
If my Sql Server Name is SQLServer\SQL2012, how do I get the full SQL Server Name in C/AL including the SQL2012 part?
Thanks
Big D signing off!0 -
Just rewrite the Automation stuff using client side DotNet (System.Xml, not the MSXML through COM interoperability)
Please note: The above code samples depend on you using the default connection.
You may find other examples using server side code, but those usually cannot cope with service instances.
You might be interested in an entirely different approach from Kauffmann @ Dynamics NAV: Read Server Settings from C/AL code, but this is undocumented and appears to be not stable across NAV versions.0 -
Thanks vaprog that's a cool way of doing that - a piece of cake
!
Big D signing off!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