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 helps 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 other a
couple of ways to find the correct Connection String.
Getting Started
Let's say, if you are looking for a job change, got short listed, during the technical round the company asked you to create an application which does simple insertions into a Database table. You are provided with Visual Studio and a 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, couple of ways there. Check below :)
1. Using Connect to Database method from Tools Menu.
Open Visual Studio, create a Web Site, and click on Tools --> Connect to Database option. Add a new data connection from
the Server Explorer window. Enter Server Name and user credentials then select the database and click on Test Connection.
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 !
Another way is to right click on the newly created connection and select properties. The Connection String property will show the actual value.
2. Using a web control (lets try with or use DropDownList)
Drag and drop a DropDownList control to your form. Click on Choose Data Source from task list; this will open the Data Source Configuration Wizard.
Select a New data source from drop down, choose a Data Source Type (example: SQL Database) and click Next.
From Choose Your Data Connection window you can create a new connection (refer to above point 1) or select existing one.
The following Connection String area will shows the actual value.
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 another way,
please free to post below.
Please post your comments and rate the article. Also, post your questions to our Forum
section.
Thank You!