RAD Studio
ContentsIndex
PreviousUpNext
Connecting to a Data Store Using TADOConnection

One or more ADO dataset and command components can share a single connection to a data store by using TADOConnection. To do so, associated dataset and command components with the connection component through their Connection properties. At design-time, select the desired connection component from the drop-down list for the Connection property in the Object Inspector. At runtime, assign the reference to the Connection property. For example, the following line associates a TADODataSet component with a TADOConnection component.

ADODataSet1.Connection := ADOConnection1;

 

ADODataSet1->Connection = ADOConnection1;

The connection component represents an ADO connection object. Before you can use the connection object to establish a connection, you must identify the data store to which you want to connect. Typically, you provide information using the ConnectionString property. ConnectionString is a semicolon delimited string that lists one or more named connection parameters. These parameters identify the data store by specifying either the name of a file that contains the connection information or the name of an ADO provider and a reference identifying the data store. Use the following, predefined parameter names to supply this information:  

Connection parameters  

Parameter 
Description 
The name of a local ADO provider to use for the connection.  
Data Source  
The name of the data store.  
File name  
The name of a file containing connection information.  
Remote Provider  
The name of an ADO provider that resides on a remote machine.  
Remote Server  
The name of the remote server when using a remote provider.  

Thus, a typical value of ConnectionString has the form

Provider=MSDASQL.1;Data Source=MQIS

Note: The connection parameters in ConnectionString do not need to include the Provider or Remote Provider parameter if you specify an ADO provider using the Provider property. Similarly, you do not need to specify the Data Source parameter if you use the DefaultDatabase property.
In addition, to the parameters listed above, ConnectionString can include any connection parameters peculiar to the specific ADO provider you are using. These additional connection parameters can include user ID and password if you want to hardcode the login information. 

At design-time, you can use the Connection String Editor to build a connection string by selecting connection elements (like the provider and server) from lists. Click the ellipsis button for the ConnectionString property in the Object Inspector to launch the Connection String Editor, which is an ActiveX property editor supplied by ADO. 

Once you have specified the ConnectionString property (and, optionally, the Provider property), you can use the ADO connection component to connect to or disconnect from the ADO data store, although you may first want to use other properties to fine-tune the connection. When connecting to or disconnecting from the data store, TADOConnection lets you respond to a few additional events beyond those common to all database connection components..

Note: If you do not explicitly activate the connection by setting the connection component's Connected property to True, it automatically establishes the connection when the first dataset component is opened or the first time you use an ADO command component to execute a command.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!