Tuesday, 8 August 2017

Using system classes to connect to database x++

Here in this topic, we will learn about how to connect SQL database using standard classes (without creating ODBC connection.

The code below uses the ODBCConnection class and LoginProperty class to connect to SQL DB.

server static ODBCConnection createConnection(str _SQLServerName, str _DatabaseName)
{
    ODBCConnection  connection;
    LoginProperty   loginProperty;
    ;
    loginProperty = new LoginProperty();
    loginProperty.setServer(_SQLServerName);


    loginProperty.setDatabase(_DatabaseName);

    connection = new ODBCConnection(loginProperty);

    return connection;
}

It will return the connection, which can be used to execute SQL statements.

No comments:

Secure API Integration in D365FO Using OAuth2 and Azure Key Vault (X++)

  Secure API Integration in D365FO Using OAuth2 and Azure Key Vault (X++) Integrating with external APIs securely is a common requirement in...