Microsoft SQL Server ODBC for macOS DSN-Less Connection
This tutorial shows how to verify your driver installation and connect to a Microsoft® SQL Server® database using a DSN-less connection string at the MATLAB® command line. A DSN-less connection string enables you to make a connection to the database without specifying a data source name (DSN). The tutorial uses the Microsoft ODBC Driver 18.1 for SQL Server to connect to a Microsoft SQL Server 2016 Express database on the Apple macOS platform.
Step 1. Verify the driver installation.
The ODBC driver is typically preinstalled on your computer. To verify that your
computer has the driver, look for the libmsodbcsql.18.dylib
driver installation in the folder
/usr/local/Cellar/msodbcsql18/18.1.2.1/lib/
. If you need to
install an ODBC driver, contact your database administrator or see Install the Microsoft ODBC Driver for SQL Server on the Microsoft
website. For details about the driver installation or troubleshooting the
installation, contact your database administrator or refer to your database
documentation on ODBC drivers.
Step 2. Connect using the DSN-less connection string and command line.
Connect to the database using the DSN-less connection string and the shipped ODBC
driver with the odbc
function. This example assumes that you are connecting to a database server
dbtb12
, the port number is 54317
,
toy_store
is the database name, username
is the user name, password
is the password, and
driverLocation
is the location of the shipped driver.
driverLocation = "/usr/local/Cellar/msodbcsql18/18.1.2.1/lib/libmsodbcsql.18.dylib"; dsnless = strcat("Driver=",driverLocation,";Server=dbtb12,54317;UID=username;PWD=password;Database=toy_store") conn = odbc(dsnless)