4 steps to establish a SQL Server connection

 Jul 04, 2014

Almost all applications that are developed these days will, at some point, connect to an external data source like SQL Server. When this need arises, you will have to establish a connection from your application to the SQL Server database. This connection contains the server’s name you are connecting to, credentials for authentication and also contains the name of the database that you want to connect to. These are only a few pieces of information that can be included in the connection. All of the information specified when setting up the connection will form part of a connection string. This connection string can be used by your application to access the database and not only retrieve information but also submit information to be saved. When we take a look at a basic connection string, for example:
“Data Source=MYSQLSERVER; Initial Catalog=AdventureWorksDB; User ID =myuser; password = mypassword”
In the connection string above, you will specify the server’s name by giving a value to the “Data Source” property, which in this case is MYSQLSERVER. You can specify the database name by providing a value to the “Initial Catalog” property. In my example, I will be using the AdventureWorksDB. The last part of the connection string is where you can specify your credentials, by providing a value for the “User ID” property and the “Password” property. Looking at this basic connection string, it can be hard to remember all properties that you want to use. Luckily there is an easier way to build this connection string! To do this, simply follow the steps below.
  1. Create a new text document anywhere you want and rename the extension to “.udl.”Defining a SQL Server connection string
  2. Open up the .udl file you have created, and you should see an interface to build the string. Press OK and then from this window, you’ll be able to select a provider, specify a server name, credentials, database name and even more options by going to the ‘Advanced’ and ‘All’ tabs. Defining a SQL Server connection string
  3. After you have specified your values, go ahead and open the .udl file in notepad. You’ll see something similar to the below image. Defining a SQL Server connection string
  4. Copy and paste this connection string to where you require it, and you are all good to go.

How do your Excel skills stack up?   

Test Now  

About the Author:

Auret Swanepoel  

As a recent addition to the New Horizons team, Auret is a highly skilled and qualified IT Technical trainer. He has been a Microsoft Certified Trainer (MCT) since 2008 and has since then, also become a Microsoft Certified Professional (MCP), a Microsoft Certified Technology Specialist (MCTS) and a Microsoft Certified Information Technology Professional (MCITP). With his international experience as a trainer in South Africa, Auret is able to adapt his teaching style to different audiences in the classroom and ensure that students are learning in a positive and collaborative environment.

Read full bio
top