我试图做这样的事情:
公用Sub(BYVAL boolTest由于布尔)
昏暗objConnecton作为System.Data.Common.DbConnection
尝试
如果boolTest然后
objConnecton =新的SqlConnection
其他
objConnecton =新的OracleConnection
结束如果
抓住EX为例外
最后
这里的清理
结束尝试
这适用于版本Oracle.DataAccess的2.112.1.0,但10.2.0.100版没有。随着10.2.0.100版本中,我得到了以下的编译错误:
型Oracle.DataAccess.Client.OracleConnection的价值不能被转换为System.Data.Common.DbConnection'
我试图初始化连接对象的任何SQLConnection或为OracleConnection根据布尔值的一个实例。
为什么我得到这个错误?
解决方案为什么我得到这个错误?
后来的(10.2+)版本的Oracle客户端的.NET不从标准的.NET框架类,如的DbConnection
导出。这需要有一个公平的更多的工作,如果你想无缝支持多个数据库,你可以不再仅仅使用基类中 System.Data.Common 。
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?
解决方案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
.
相关推荐
最新文章