Main Content

Microsoft SQL Server ODBC for Windows 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 command line. (DSN is a data source name.) The tutorial uses the Microsoft ODBC Driver 13.1 for SQL Server to connect to a Microsoft SQL Server 2016 Express database on the Windows® platform.

Step 1. Verify the driver installation.

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.

Note

Database Toolbox™ no longer supports connecting to a database using a 32-bit driver. Use the 64-bit version of SQL Server. If you have issues working with the ODBC driver, use the JDBC driver instead. For details, see Microsoft SQL Server JDBC for Windows. For details about working with the 64-bit version of Windows, see Using Previous MATLAB Releases.

Step 2. Connect using the DSN-less connection string and command line.

  1. Connect to the database using the DSN-less connection string with the odbc function. For example, this code assumes that you are connecting to the local database server, port number 1433, database name toystore_doc, user name username, and password pwd.

    dsnless = strcat("Driver={SQL Server Native Client 13.1}; Server=localhost\toystore_doc;", ...
       "Port=1433; Database=toystore_doc; UID=username; PWD=pwd");
    conn = odbc(dsnless);
  2. Close the database connection.

    close(conn)

See Also

|

Related Topics