Connection Strings Explained Print

  • 0

Connection Strings Explained

Introduction

When your application connects to a database or a data file you let ADO or ADO.Net utilize a provider to do the job for you. The connection string contains the information that the provider need to know to be able to establish a connection to the database or the data file.

Because there are different providers and each providers have multiple ways to make a connection there are many different ways to write a connection string. It's like the address when sending a regular mail. Depending on the origin and destination and who is going to make the transport you need to write down the address in different ways.

For example; the provider needs the address to the server (or the path to the data file) to connect to. This parameter is often named "Server" or "Data Source". The value specified for this key in the connection string is passed on to the provider and this is how its possible for the provider to know where to connect.

 

Keystones

A connection string consists of a series of keyword - value pairs separated by semicolons (;)

The equal sign (=) connects each keyword and its value

Example: Key1=Value1;Key2=Value2;Key3=Value3;

The information in the connection string is passed on to the provider

 

Okay, I get it, but where are those connection strings located?

The connection string is really just a string inside your application. There is no ODBC DSN admin kind of program for connection strings. You just write your connection string and pass it on to your connection object. The property is named ConnectionString or is passed through the Open function of your connection object.

Summary

There isn't any magic when working with connection strings. The basic idea is quite simple. What often cause problems is when values are improperly set. Sometimes the connection string will work in the development environment, then when moved to production, the application fails. To take some extra minutes and think about each property and read about each of them on these pages will most likely pay off in terms of development time, availability and performance.

 


Was this answer helpful?

« Back