Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET and Oracle data access

Tags:

.net

oracle10g

I am trying to do something like this:

Public Sub (ByVal boolTest As Boolean)
Dim objConnecton As System.Data.Common.DbConnection
Try

  If boolTest Then
         objConnecton = New SqlConnection
  Else
          objConnecton = New OracleConnection 
  End If
  Catch ex As Exception

Finally
  'Cleanup here
End Try

This works with version 2.112.1.0, of Oracle.DataAccess, but does not with version 10.2.0.100. With version 10.2.0.100, I get the following compilation error:

"Value of type 'Oracle.DataAccess.Client.OracleConnection' cannot be converted to 'System.Data.Common.DbConnection'"

I am trying to initialise the connection object with an instance of either SQLConnection or OracleConnection depending on the value of the Boolean.

Why do I get this error?

like image 278
w0051977 Avatar asked May 31 '26 07:05

w0051977


1 Answers

Why do I get this error?

The later (10.2+) versions of the Oracle clients for .NET do not derive from the standard .NET framework classes, such as DbConnection. This has the unfortunate side effect of requiring a fair bit more work if you want to support multiple databases seamlessly, as you can no longer just use the base classes in System.Data.Common.

like image 126
Reed Copsey Avatar answered Jun 01 '26 22:06

Reed Copsey