Oracle Database Interaction Using ODP.NET and ASP.NET: All Possible Ways To Get Connected - Connecting to Oracle using the .NET Framework Data Provider for OLEDB
(Page 2 of 6 )
The .NET Framework Data Provider for OLE DB requires the installation of MDAC 2.6 or later. It uses native OLE DB through “COM interop” to enable data access. To use the .NET Framework Data Provider for OLE DB, you must use an OLE DB provider. All classes for “.NET Framework Data Provider for OLE DB” are located in the System.Data.OleDb namespace.
One of the most important issues to remember is that the .NET Framework Data Provider for OLE DB does not work with the OLE DB Provider for ODBC (MSDASQL). To access an ODBC data source using ADO.NET, use the .NET Framework Data Provider for ODBC.
Now we shall test an example for connecting to and accessing data from an Oracle database using the .NET Framework Data Provider for OLEDB.
Imports System.Data.OleDb
.
.
Dim cn As New OleDbConnection("Provider=msdaora;Data
Source=ORCL;User Id=scott;Password=tiger;")
Try
Dim da As New OleDbDataAdapter("select * from
scott.emp", cn)
Dim dt As New OleDbData
da.Fill(dt)
da.Dispose()
Me.DataGrid1.DataSource = dt
Me.DataGrid1.DataBind()
dt.Dispose()
Cath ex As Exception
Me.lblError.Text = ex.Message
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
Those who are familiar with System.data.SqlClient (.NET Framework Data Provider for Microsoft SQL Server) would find the above code quite understandable. Connection, Command, Reader and DataAdapter are the four important objects (for connectivity and data access) which would be available with almost every .NET provider. All of those four objects are preceded by the type of .NET provider (ex: oledbConnection, odbcConnection, sqlConnection, and so forth).
To work with the above code, I registered and configured a service name “ORCL” (using Net Configuration Assistant) at my client (Oracle Client), which has been specified as the data source with in the “connection string” above. The above example is demonstrated in “webform3” of the downloadable.
Next: Connecting to Oracle using .NET Framework Data Provider for ODBC >>
More ASP.NET Articles
More By Jagadish Chaterjee