asp connection

 

The OLE DB .NET Data Provider provides connectivity to data sources exposed using OLE DB and to Microsoft SQL Server version 6.x or earlier (through SQLOLEDB, the OLE DB Provider for SQL Server), using the OleDbConnection object.

For the OLE DB .NET Data Provider, the connection string format is identical to the connection string format used in ADO, with the following exceptions:

For more information about OLE DB connection strings, see "Creating the Connection String" in the Platform SDK Documentation located in the MSDN library.

Note   Using Universal Data Link (UDL) files may slow performance. You can use UDL files to supply OLE DB connection information to the OLE DB .NET Data Provider. However, because UDL files can be modified externally to any ADO.NET client program, connection strings that contain references to UDL files will be parsed every time the connection is opened. This can slow performance and it is therefore recommended, for best performance, that you use a static connection string that does not include a UDL file.

The following code example demonstrates how to create and open a connection to an OLE DB data source.

[Visual Basic]
Dim nwindConn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" & _
                                                       "Integrated Security=SSPI;Initial Catalog=northwind")
nwindConn.Open()
[C#]
OleDbConnection nwindConn = new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" +
                                                "Integrated Security=SSPI;Initial Catalog=northwind");
nwindConn.Open();

Closing the Connection

You must always close the Connection when you are finished using it. This can be done using either the Close or Dispose methods of the Connection object. Connections are not implicitly released when the Connection object falls out of scope or is reclaimed by garbage collection.