Declaring a .NET package in future version of AL for Business central on prem

Salit Mayshar 0 Reputation points
2025-11-26T22:08:16.4266667+00:00

Interact with an external database from BC onprem AL — will it allows direct SQL CRUD to a non-BC database. using .net package like

 SQLConnection: DotNet SqlConnection;
        SQLCommand: DotNet SqlCommand;
        SQLDataAdapter: DotNet SqlDataAdapter;
        DataTable: DotNet DataTable;
        ConnectionString: Text;
Developer technologies | .NET | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-26T22:08:24.0033333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    In Business Central AL, you can interact with external databases using .NET interoperability. This allows you to perform SQL CRUD operations on a non-BC database using the .NET classes such as SqlConnection, SqlCommand, and SqlDataAdapter.

    To declare a .NET package in AL, you would typically follow these steps:

    1. Declare the .NET types in your AL code using the DotNet keyword.
    2. Establish a connection to the external database using SqlConnection.
    3. Execute commands using SqlCommand and manage data with SqlDataAdapter and DataTable.

    Here’s a simplified example of how you might declare these types:

    SQLConnection: DotNet SqlConnection;
    SQLCommand: DotNet SqlCommand;
    SQLDataAdapter: DotNet SqlDataAdapter;
    DataTable: DotNet DataTable;
    ConnectionString: Text;
    

    This setup allows you to perform direct SQL operations on the specified external database, provided that you have the necessary permissions and the connection string is correctly configured. However, ensure that your Business Central environment is set up to allow such operations, as there may be restrictions based on your deployment and security settings.


  2. Varsha Dundigalla(INFOSYS LIMITED) 3,725 Reputation points Microsoft External Staff
    2025-11-27T07:33:30.44+00:00

    Thank you for reaching out.

    You can use .NET types in AL to connect to external SQL databases only in Business Central On-Premises. For on-prem, set "target": "OnPrem" in app.json and declare .NET types like SqlConnection, SqlCommand, and SqlDataAdapter using the DotNet keyword. Make sure you reference assemblies such as Microsoft.Data.SqlClient and configure connection strings and permissions correctly.

    For Business Central Online (SaaS), .NET interoperability is not supported because the environment is sandboxed. The recommended approach is to use web APIs (OData, REST, SOAP) or call external services via AL HttpClient or Azure Functions. This ensures security, upgrade compatibility, and future migration readiness.

    I recommend using APIs even for on-prem because direct SQL bypasses Business Central’s security and business logic.

    References:

    Please let us know if you require any further assistance, we’re happy to help.

    If you found this information useful, kindly mark this as "Accept Answer".


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.