接続の作成

適用先: Access 2013、Office 2013

データ ソースに接続するには、接続文字列を指定する必要があります。パラメーターはプロバイダーとデータ ソースごとに異なる場合があります。 For more information, see Creating the Connection String.

ADO では、多くの場合、 Connection オブジェクトの Open メソッドを使用して接続を開きます。 Open メソッドの構文は次のとおりです。

Dim connection as New ADODB.Connection 
connection.Open ConnectionString, UserID, Password, OpenOptions

または、ショートカット手法 Recordset.Open を呼び出して暗黙的な接続を開き、その接続に対してコマンドを 1 回の操作で発行することもできます。 これを行うには、ActiveConnection 引数として有効な接続文字列を Open メソッドに渡します。 Visual Basic の各メソッドの構文を次に示します。

Dim recordset as ADODB.Recordset 
Set recordset = New ADODB.Recordset 
recordset.Open Source, ActiveConnection, CursorType, LockType, Options

注:

[!メモ] Connection オブジェクトと Recordset.Open ショートカットの使い分けは次のようになります。 複数の Recordset を開く予定がある場合や、複数のコマンドを実行する場合は、 Connection オブジェクトを使用します。 Recordset.Open ショートカットを使用した場合でも、ADO によって接続が暗黙的に作成されます。