This tutorial shows how to set up a data source and connect to a Microsoft® SQL Server® database using the command line. The tutorial uses the Microsoft ODBC Driver 13.1 for Microsoft SQL Server to connect to a Microsoft SQL Server 2016 Express database on the Linux® platform.
The ODBC driver is typically preinstalled on your computer. For details about the driver installation or troubleshooting the installation, contact your database administrator or refer to your database documentation on ODBC drivers.
If you need to install an ODBC driver, contact your database administrator or see Install the Microsoft ODBC Driver for SQL Server (Linux).
Follow the instructions in Connecting to SQL Server to create a data source name (DSN).
Connect to the database using the configured DSN, user name
username, and password
odbc function. For example, this code assumes that you are
connecting to an ODBC data source
datasource = "MSSQL"; username = "username"; password = "pwd"; conn = odbc(datasource,username,password);
Close the database connection.