Connect To A Database From Visual Studio

Introduction

You may, at times, not want to install SQL Server Management Studio (SSMS) on a machine because of the size or some other reason. So, don’t worry. You can connect to your database directly from Visual Studio.

Prerequisites

 

  • Visual Studio (Preferably 2010 and above)
  • SQL Server Instance running on any machine.

 

The example contains Visual Studio 2015 and SQL Server Instance 12.0.2269.0.

Solution

Open Visual Studio.


Go to "Tools" menu and then click on "Connect to Database".


The "Add Connection" window opens.


First, you need to choose the type of database to which you want to connect. MS SQL Server is pre-selected.

In the Server Name, type the IP and Instance of your Server. In this example, we will be connecting to a local instance of SQL Server, so I’ve entered dot (.).

Select Authentication. (Again, since it's local, I’ve selected Windows Authentication.). Selecting SQL Server Authentication, you can enter username and password.

Below are the authentication types available.


Then, select the required database from the drop down or you can type it.

For advanced setting, click "Advanced…"

You can also click on "Text Connection" to see if the details entered by you are correct and are able to connect to the SQL Server Instance.


Once done, click OK.


The database connection will now show in the "Server Explorer" tab. If you can’t see it, go to "View" menu and click "Server Explorer".


It will open the tab.


Note

By default, you can connect to the below types of databases.


If you need to connect to databases other than these, then you will need to install appropriate SDK. For example, if you want to connect to MySQL database, then you need to download the installer from here.

Conclusion

Now, you’ll be able to access your database directly from Visual Studio. You can follow the same procedure to connect to any other type of database.


Similar Articles