Generate or find Connection String from Visual Studio

Introduction

This article is about how to generate or find and where to find or how to know the correct Database Connection String for your application. Now you all might think, what will be the big deal about knowing what the actual Connection String is? Most of the people will do a web search and copy and paste into the project, there will be a 50-50 chance of successful working of the Connection String. This article will help and show a simple way to generate or find the correct Connection String that will run without an error for the project. Also, I will list a couple of ways to find the correct Connection String.

Getting Started

Let's say, you are looking for a job change and got shortlisted, during the technical round the company asked you to create an application that does simple insertions into a Database table. You are provided with Visual Studio and an SQL Client. If it's your lucky day then the Connection String you used will work for you like a charm. But, if that doesn't work what will you do, how will I find the correct Connection String?

So how will you find the correct Connection String? It's simple, a couple of ways there. Check below.

Step 1. Use the Connect to Database method from the Tools Menu.

Open Visual Studio, create a Web Site, and click on Tools --> Connect to Database option. Add a new data connection from

 Connect to Database

If the connection is successful then click on Advanced; that will open the properties window. Below the Data Source, you can find the actual Connection String. So your Connection String got generated, it simple huh?

Data Source

Another way is to right-click on the newly created connection and select properties. The Connection String property will show the actual value.

Connection String property

Step 2. Using a web control (let's try with or use DropDownList)

Drag and drop a DropDownList control to your form. Click on Choose Data Source from the task list; this will open the Data Source Configuration Wizard.

DropDownList

Select a New data source from the dropdown, choose a Data Source Type (example: SQL Database), and click Next.

Data Source Type

From the Choose Your Data Connection window you can create a new connection (refer to above point 1) or select an existing one.

The following Connection String area will show the actual value.

Data Connection window

That's it. You can even test the database connection with the preceding process without writing a single line of code.

Conclusion

I tried to show different ways to generate the correct Connection String using Visual Studio.

Hope this article helped you. If you know any other way, please free to post below.

Please post your comments and rate the article. Also, post your questions in our Forum section.

Thank You!


Similar Articles