SQL from NAV - connection string

ScottForsyth
Member Posts: 2
Hello,
We have a NAV application that makes a direct SQL query from the NAV C/AL code. We need to do it to leverage some non-NAV functionality, and it works well except for one thing.
We want to be able to get the NAV server and NAV database dynamically from the C/AL code. Right now we hardcode the connection information within the CodeUnit, but we want to get away from that.
I haven't had any luck yet in finding out how to obtain the database server and name from C/AL, but I assume it must be possible. Any ideas on how to do that?
Thanks,
Scott
We have a NAV application that makes a direct SQL query from the NAV C/AL code. We need to do it to leverage some non-NAV functionality, and it works well except for one thing.
We want to be able to get the NAV server and NAV database dynamically from the C/AL code. Right now we hardcode the connection information within the CodeUnit, but we want to get away from that.
I haven't had any luck yet in finding out how to obtain the database server and name from C/AL, but I assume it must be possible. Any ideas on how to do that?
Thanks,
Scott
0
Best Answer
-
You can query the service tier settings.
VAR
Name: ServerUserSettings
Type: DotNet
Subtype: Microsoft.Dynamics.Nav.Types.ServerUserSettings.’Microsoft.Dynamics.Nav.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′
FUNCTION
GetSQLServerName() : Text
{
ServerUserSettings := ServerUserSettings.Instance();
IF FORMAT(ServerUserSettings.DatabaseInstance) <> '' THEN
EXIT(STRSUBSTNO('%1\%2',DatabaseServer,ServerUserSettings.DatabaseInstance));
EXIT(FORMAT(ServerUserSettings.DatabaseInstance));
}Follow me on my blog juhl.blog6
Answers
-
What's the NAV version
Regards.0 -
You can query the service tier settings.
VAR
Name: ServerUserSettings
Type: DotNet
Subtype: Microsoft.Dynamics.Nav.Types.ServerUserSettings.’Microsoft.Dynamics.Nav.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35′
FUNCTION
GetSQLServerName() : Text
{
ServerUserSettings := ServerUserSettings.Instance();
IF FORMAT(ServerUserSettings.DatabaseInstance) <> '' THEN
EXIT(STRSUBSTNO('%1\%2',DatabaseServer,ServerUserSettings.DatabaseInstance));
EXIT(FORMAT(ServerUserSettings.DatabaseInstance));
}Follow me on my blog juhl.blog6 -
Thanks Juhl! That worked. I support a few different NAV instances, but it works for the current versions (10.0.0.0), and for the older versions I just found the DLL and copied to the add-ins folder and then it's available to reference and use.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