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;
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.
Ahmed Rashed Amini
Independent Consultant/Developer
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.
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.
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);
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
Answers
Create(MSDOM);
MSDOM.load(APPLICATIONPATH+ 'CustomSettings.config');
MSNode := MSDOM.SelectSingleNode('// Location of DatabaseServer key');
Message(MSNode.Value);
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
It works indeed: \:D/
Object Manager
All I did was guide him to the right path.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
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?
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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.
Thanks deV.ch
WSHNetwork.Computername was just what I needed.
:P
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
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.