asp.net.ph

OleDbConnection.Open Method

System.Data.OleDb Namespace   OleDbConnection Class


Opens a database connection with the property settings specified by the ConnectionString.

[ VB ]
NotOverridable Public Sub Open ( )

[ C# ]
public void Open ( );

[ C++ ]
public: __sealed void Open ( );

[ C++ ]
public function Open ( );

Exceptions


Exception Type Condition
InvalidOperationException Occurs when the connection is already open.
OleDbException Occurs when a connection-level error occurred while opening the connection.

Remarks

The OleDbConnection draws an open connection from the connection pool if one is available. Otherwise, it establishes a new connection to the data source.

NOTE: If the OleDbConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close or Dispose.

Example

The following example initializes and opens an OleDbConnection, displays some of its properties, then closes the connection.

protected void Page_Load ( Object Src, EventArgs e ) {
   // specify the data source
   OleDbConnection myConn = new OleDbConnection (
      "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + 
      Server.MapPath ( "~/app_data/pubs.mdb" ) );
   // open the data connection
   myConn.Open ( );

   // retrieve properties of the connection object
   ...

   // close the data connection
   myConn.Close ( );
}

 Show me 

See Also

OleDbConnection Members   Close   StateChange Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph