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 Oracle
(Page 4 of 6 )
The .NET Framework Data Provider for Oracle (or Microsoft’s Data Provider for Oracle) enables data access to Oracle data sources through Oracle client connectivity software. The data provider supports Oracle client software version 8.1.7 and later. The .NET Framework Data Provider for Oracle requires that Oracle client software (version 8.1.7 or later) be installed on the system before you can use it to connect to an Oracle data source.
All classes for the “.NET Framework Data Provider for Oracle” are located in the System.Data.OracleClient namespace and are contained in the System.Data.OracleClient.dll assembly. You will need to reference both the System.Data.dll and the System.Data.OracleClient.dll when compiling an application that uses the data provider. If you are using .NET Framework 1.0 (or Visual Studio.NET 2002), you need to download and install the provider (which is not provided by default) from http://msdn.microsoft.com/downloads.
Now we shall test an example of connecting and accessing data from an Oracle database using .NET Framework Data Provider for Oracle.
Imports System.Data.OracleClient
.
.
Dim cn As New OracleConnection("Data Source=ORCL;User
Id=scott;Password=tiger;")
Try
DimdaAsNewOracleDataAdapter("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
The explanation for the above code is very similar to that of the previous sections (mainly I replaced all “odbc” with “oracle” everywhere). But, you need to look carefully at the “imports” statement and “connection string” I specified above. The above example is demonstrated in “webform2” of the downloadable.
Next: Connecting to Oracle using ODP.NET (Oracle Data Provider for .NET) >>
More ASP.NET Articles
More By Jagadish Chaterjee