OleDbConnection.Open 方法

定义

使用由 ConnectionString 指定的属性设置打开一个数据库连接。Opens a database connection with the property settings specified by the ConnectionString.

public:
 virtual void Open();
public void Open ();
override this.Open : unit -> unit
Public Sub Open ()

实现

异常

连接已打开。The connection is already open.

打开连接时出现的连接级别错误。A connection-level error occurred while opening the connection.

注解

OleDbConnection 从连接池中绘制打开的连接(如果有)。The OleDbConnection draws an open connection from the connection pool if one is available. 否则,它将建立与数据源的新连接。Otherwise, it establishes a new connection to the data source. 可在单个 OleDbConnection上打开多个 DataReader。You can open more than one DataReader on a single OleDbConnection. 如果你使用的 OLEDB 提供程序在单个连接上不支持多个活动的 DataReader,则 OLEDB 访问接口将为每个连接隐式打开一个其他连接。If the OLEDB provider you use does not support more than one active DataReader on a single connection, the OLEDB provider implicitly opens an additional connection for each.

备注

如果 OleDbConnection 超出范围,则它不会关闭。If the OleDbConnection goes out of scope, it is not closed. 因此,必须通过调用 CloseDispose,或在 Using 语句中使用连接来显式关闭连接。Therefore, you must explicitly close the connection by calling Close or Dispose, or using the connection within a Using statement.

适用于

另请参阅