About Connection Strings
A connection string is a string version
of the initialization properties needed to connect to a database and enables
you to easily store connection information or to pass it between applications.
Without a connection string, you would be required to store or pass a
complex array of structures to access data. When accessing OLE DB the
connection string is passed as a parameter to create an OLE DB data source
object.
In some cases, rather than using the standard data
link user interface, it might be desirable to build a connection string
within an application—for example, if you want to fine-tune the database
connection properties. In these cases, it is important that the connection
string syntax adhere to the formatting rules described in the following
sections.
Basic Connection String Format
The basic format of a connection string is based on the ODBC connection
string. The string consists of a series of keyword/value pairs separated
by semicolons. The equal sign (=) connects each keyword and its value.
Example: keyword1=value; keyword2=value
The Provider Keyword
The Provider keyword identifies the OLE DB provider to be used.
To specify your OLE DB provider, set the value of the Provider
keyword to the VersionIndependentProgID value of the provider.
Example: Provider=MSDASQL
The value can also be set to the ProgID of the provider, which may have
a version attached to it.
Example: Provider=MSDASQL.1
If two versions of a provider are installed on the same system, use
the ProgID to specify exactly which version to use. If two versions are
installed on a system and the VersionIndependentProgID value is
specified, the most recent version of the provider is used.
If no Provider keyword is in the string, the OLE DB Provider
for ODBC (MSDASQL) is the default value. This provides backward compatibility
with ODBC connection strings. The ODBC connection string in the following
example can be passed in, and it will successfully connect.
Example: Driver={SQL Server};Server=MyServer;db=pubs;uid=sa;pwd=MyPassword
If the Provider keyword is specified but names a provider that
does not exist or is invalid, as in the following example, an error is
returned.
Example: Provider=;Database=MyDatabase
Specifying a Keyword
To identify a keyword used after the Provider keyword, use the
property description of the OLE DB initialization property that you want
to set. For example, the property description of the standard OLE DB initialization
property DBPROP_INIT_LOCATION is Location. Therefore, to include this
property in a connection string, use the keyword Location.
Example: Provider=MSDASQL;Location=Pubs
Note Standard OLE
DB properties are documented under the OLE DB Initialization property
group (DBPROPSET_DBINIT) in Appendix C: OLE DB Properties. For information
about provider-specific initialization properties, see the documentation
that came with your provider.
Keywords can contain any printable character except for the equal sign
(=). All of the following examples are correct.
Example: Jet OLE DB:System Database=c:\system.mda
The keyword is "Jet OLE DB:System Database".
Example: Authentication;Info=Column 5
The keyword is "Authentication;Info".
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.
Example: Verification==Security=True
The keyword is "Verification=Security".
If multiple equal signs appear, each one must be preceded by an additional
equal sign.
Example: Many====One=Valid
The keyword is "Many==One".
Example: TooMany===False
The keyword is "TooMany=".
Related Topics:
Connection properties
About database connections
Connect to existing database
Object Browser elements
Open Microsoft
Access files with the program
Create
a shortcut to a database on the Shortcut Bar
|