Connect Microsoft Visual Studio to MySQL

This topic describes how to connect Microsoft Visual Studio to a MySQL database using the ODBC driver.

Visual Studio is a powerful development environment that provides tools for editing, debugging, and compiling code, as well as creating applications. These applications can connect to databases and services on a local machine, across a network, or in any cloud environment—private, public, or hybrid. To connect Visual Studio to a data source such as MySQL, you can use Devart ODBC driver for MySQL.

Create a DSN for MySQL

Before you start, you need to configure a DSN for MySQL in the ODBC Data Source Administrator. It’s required to establish a connection to an ODBC database in Visual Studio. You can find the instructions for your OS in the following topics:

  • Configure a Windows DSN for MySQL.
  • Create a DSN on macOS.
  • Create a DSN on Linux.

Connect Visual Studio to MySQL

1. Open Microsoft Visual Studio.

2. Open Server Explorer: On the View menu, select Server Explorer.

3. In Server Explorer, right-click Data Connections and select Add Connection.

4. In the Choose Data Source dialog, select Microsoft ODBC Data Source and click Continue.

Connect Visual Studio to MySQL - Select Data Source

5. In the Data source specification section, select your MySQL DSN from the Use user or system data source name dropdown list.

6. Optional: Click Test Connection to verify connectivity.

Connect Visual Studio to the data source - Test Connection

7. Click OK.

The new connection appears under Data Connections in Server Explorer.

Connect Visual Studio to the data source - Connection created