Computer Services
professional website developers

ADO.NET

Home
About Us
Our Services
Contact Information
Articles
 

Connection strings explained

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 key 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.

  • 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

Okey, I get it, but where are those connection strings located?
Well, 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.

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.

There are some important rules that is good to know about when working with connection strings.

 

Important rules for connection strings

This is general rules adopted by most drivers and providers. However, keep in mind that these rules is not 100% accurate for every driver and every situation.

Never the less, following and knowing about these basic rules will keep some common problems out of your way. Okay? Here we go..

           
  • All blank characters, except those placed within a value or within quotation marks, are ignored

  • Any leading or trailing spaces around a keyword or value are ignored

  • If a semicolon (;) is part of a value it must be delimited by quotation marks (")

  • To include values that contain a semicolon (;), single-quote character ('), or double-quote character ("), the value must be enclosed in double quotes (")

  • No escape sequences are supported

  • The value type is not relevant

  • Names are case iNsEnSiTiVe

  • If a property name occurs more than once in the connection string, the value associated with the LAST occurrence is used

  • But... if the Provider keyword occurs multiple times in the string, the FIRST occurrence is used.

  • If a keyword contains an equal sign (=), it must be preceded by an additional equal sign to indicate that it is part of the keyword.

  • Use a single-quote (') if the value begins with a double-quote (")

  • Conversely, use the double quote (") if the value begins with a single quote (')
A & G Web Development and Design
30-14 Garrison Ter., Fair Lawn NJ 07410
(201) 937-8711