Formating Rules for Connection Strings

There are no built in checks or constraints on how to format a connection string. This walk-through shows the basic rules for creating a connection string that will work.
Written by: Mark Lurade

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 the way.

The rules

  • All blank characters, except those placed within a value or within quotation marks, are ignored
  • Blank characters will though affect connection pooling mechanism, pooled connections must have the exact same connection string
  • If a semicolon (;) is part of a value it must be delimited by quotation marks (")
  • 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 (')
  • No escape sequences are supported
  • The value type is not relevant
  • Names are case iNsEnSiTiVe
  • If a KEYWORD=VALUE pair occurs more than once in the connection string, the value associated with the last occurrence is used
  • However, 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.
  • If a value has preceding or trailing spaces it must be enclosed in single- or double quotes, ie Keyword=" value ", else the spaces are removed.

Summary

Knowing about these basic rules will keep hard to track errors away from you. Take some time understanding these rules and a couple of minutes choosing what parameters to specify when connecting your application to the data source.

Connect to