web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Is it possible to access SQL from C/AL?

(0) ShareShare
ReportReport
Posted on by 179

I need to get data from another databases. I tryied using linked objects and it works but it is too slow and expensive as I need a table for each view.

Is it possible to connect to a SQL Server and run a command? Maybe with an automation or DotNet variable?

It would be perfect if I can tun this: Select * from MyTable and read the rows. So I can generate a temporaly table and run a page.

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,278 Super User 2026 Season 1 on at

    Yes, you can connect to SQL and execute the query or stored procedure. Below is an example using DotNet "'System.Data Variables

    GetSQLConnectionString returns the connection string

    'Data Source=' + "SQL Server Name" + ';'
    
                             + 'Initial Catalog=' + "SQL Database Name" + ';'
    
                             + 'Uid=' + "SQL UserID" + '; '
    
                             + 'Pwd=' + "SQL Password" + ';'
    
    SQLConnection    := SQLConnection.SqlConnection(GetSQLConnectionString);
    
         SQLCommand := SQLCommand.SqlCommand();
    
         SQLCommand.Connection := SQLConnection;
    
         SQLConnection.Open;
    
         SQLCommand.CommandText :=  'sp_abcd';
    
         SQLCommand.CommandType := SQLCommand.CommandType.StoredProcedure;
    
         SQLCommand.CommandTimeout := 120;
    
        // If you have parameters you need to add parameters using the SQL Parameter      
    
         SQLParameter := SQLParameter.SqlParameter;
    
         SQLParameter.ParameterName := '@CustomerNo';
    
         SQLParameter.SqlDbType := SQLParameter.SqlDbType.VarChar;
    
         SQLParameter.Direction := SQLParameter.Direction.Input;
    
         SQLParameter.Size := 50;
    
         SQLParameter.Value:=CustNo;
    
         SQLCommand.Parameters.Add(SQLParameter);
    
         SQLCommand.ExecuteScalar;
    
         SQLConnection.Close;
    
         SQLConnection.Dispose;


  • Jaime Figueras Profile Picture
    179 on at

    Thanks for your reply. It sound great. What if I cant Find System.Data.Variables...?

    7446.Nav.jpg

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
TAHER_El_Mehdi Profile Picture

TAHER_El_Mehdi 2

#1
sliderxb Profile Picture

sliderxb 2

#1
broberts Profile Picture

broberts 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans