Since most of the tables for Microsoft Dynamics GP are managed by SQL Server, your integration may have to interact with SQL Server directly. For example, you may need to execute stored procedures to perform tasks for your integration. Microsoft Dynamics GP provides some infrastructure that makes working with SQL Server easier in your integration.
You may need to retrieve the names of the system database, or of specific company databases. To retrieve the name of the system database (the database that contains the core accounting system tables) use the following code:
local string database_name; local boolean result; database_name = SQL_GetDbName(DYNAMICS, DYNAMICS, 7, 0, result);
To retrieve the name of the database for the current company, you can use the Intercompany ID global variable. This variable is automatically set to the name of the database for the current company.
local string database_name; database_name = 'Intercompany ID' of globals;
For some aspects of your integration, you may need to use pass-through SQL. Pass-through SQL requires an additional connection to the SQL server when being executed. To make managing these pass-through connections easier, Microsoft Dynamics GP provides an infrascture for these connections. The SQL_GetConnection() function is used to retrieve a pass-through SQL connection from Microsoft Dynamics GP. Using a connection maintained by the core application is much more efficient than opening a separate pass-through connection for your integration.