ODBC Connection in Dynamics 365 F&O

When we create the ODBC Connection in Dynamics 365 F&O?

We create an ODBC connection in D365F&O when we need to read and write data on the DB from D365F&O,
initially, we need a DB in SQL Server with which will make the connection.

The exemple code to create connection:

public void initialize() 
    str connectionStr; 
    int addedOccurrence; 
    setup = InterfaceParameters::find(); 
    //connectionString = strfmt("UID=%1;PWD=%2", user, pass); 
    loginProp = new LoginProperty(); 
    //if (tParameters.UserName) 
    //    loginProperty.setOther(connectionString); 
    //if (tParameters.Dns) 
    //    loginProperty.setDSN(tParameters.Dns); 
    //Create a connection to external database 
    conn = new OdbcConnection(loginProp); 
        conn = new  OdbcConnection(loginProp); 
        throw error("Accesso non riuscito al database specificato."); 

InterfaceParameters is the table when we save all parameters of DB connection.

After we have connected successfully we need to read or write data in the DB, below is an exemple of inserting data.

private void generateInsertQuery(TableLinkedServer _Table) 
    if(_Table == TableLinkedServer::Dipendente) 
        pushSQLStatement = "INSERT INTO " + strFmt("[%1]..[%2].[%3] ", setup.LinkedServerName, setup.LinkedServerSchema, setup.LinkedServerTableDipendende) + 
                                    "(" + this.getFieldsDipendente() + ")" + 
                      " VALUES(" + this.getValuesDipendente() + ")"; 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s