The Connection Object - The Open Method
(Page 5 of 15 )
This method opens a connection to a data source so that commands can be executed against it.
Connection.Open([ConnectionString], [UserID], _
[Password], [Options]
| Parameter | Type | Description |
|---|
| Connection String | String | Connection information |
| (optional) | | |
UserID (optional) | String | User name to use when connecting |
| Password (optional) | String | User password to use when connecting |
| Options (optional) | Long | Extra connection options (adConnectUnspecified default value) |
Options can be one of the ConnectOptionEnum constants. At the moment, the only constants supported are adAsyncConnect (which indicates the connection should be made asynchronously) and adConnectUnspecified (the default, which indicates a synchronous connection is to be made).
The ConnectionString property takes its value from the ConnectionString argument if used.
Values passed in the UserID and Password arguments override similar values passed in the ConnectionString argument-unless the Password you supply in the argument is blank, in which case the ConnectionString password still seems to take effect.
Under version 2.8, connecting to the data source depends upon the zone in which the data source originates and whether the provider supports Integrated Security (SQL, MSDataShape, Remote, and Directory Services). If the provider supports Integrated Security and the user credentials are supplied as part of the connection string, the connection is always allowed. If the provider supports Integrated Security and the credentials aren’t supplied (i.e., the current user credentials are used), or the provider doesn’t support Integrated Security, then the connection depends upon the IE settings for user authentication and logon, which can be:
- Automatic logon with current user name and password-the connection is allowed.
- Prompt for user name and password-the connection is not allowed.
- Automatic logon only in Intranet zone-the user is prompted with a security warning.
- Anonymous logon-the connection is not allowed.
Some typical connections strings are shown in the following examples. For the ODBC Provider connecting to an Access database, you would use:
Driver={Microsoft Access Driver (*.mdb)}; DBQ=database_file
The DBQ argument points to the physical path name of the Access database. To connect to SQL Server, again using ODBC, you would use:
Driver={SQL Server}; Server=server_name;
Database=database_name;
UID=user_name; PWD=user_password
Switching over to the native OLE DB drivers, connecting to Access would be like this:
Provider=Micrsoft.Jet.OLEDB.4.0; Data Source=database_file
For SQL Server, using the native driver, it would be:
Provider=SQLOLEDB; Data Source= server _ name; Initial
Catalog= database _ name; User Id= user _ name;
Password= user _ password
More details of the different connection strings you can use for the more common OLE DB Providers appear under the ConnectionString property and in Chapter 2.
This is from ADO Programmer's Reference, by Dave Sussman (Apress, ISBN 1590593421). Check it out at your favorite bookstore today. Buy this book now. |
Next: The OpenSchema Method >>
More ASP.NET Articles
More By Apress Publishing