The Open Method

This method opens a connection to the data source, and has the following syntax:

connection.Open ConnectionString, UserID, Password, Options

The ConnectionString argument serves the same purpose as the ConnectionString property discussed in the previous section. ADO allows you to set this property in advance or pass it in at the time you open the connection. The UserID and Password arguments can be passed separately from the connection string if you wish.

The Options argument is particularly interesting. This argument allows you to make your connection asynchronously. That is, you can tell your Connection object to go off and open the connection in the background while your code continues to run. You do this by setting the Options argument to the ConnectOptionEnum value adAsyncConnect. The following code sample demonstrates making an asynchronous connection:

objConn.Open Options:=adAsyncConnect

This is especially useful in situations where you have lengthy connection times, because it allows you to connect without freezing your application during the connection process.

0 0

Post a comment