开发者

Can I connect to an Oracle database in a way that will work in a Mono environment (on Linux) and in a ClickOnce deployment (on Windows)?

开发者 https://www.devze.com 2022-12-27 04:47 出处:网络
Obviously I\'d like to not have to install an Oracle client (other than simply a DLL), because that would prohibit my ClickOnce goal.I tried System.Data.OracleClient, but it threw an exception, \"Syst

Obviously I'd like to not have to install an Oracle client (other than simply a DLL), because that would prohibit my ClickOnce goal. I tried System.Data.OracleClient, but it threw an exception, "System.Data.OracleClient requires Oracle client software version 8.1.7 or greater."

Update:

It seems that System.Data.OracleClient is not the way to go. So I downloaded the xcopy-able version of the Oracle ODP.NET provider. I then ran "install.bat odp.net20 c:\oracle odac" to install only ODP.NET. Then I added a reference in my project to C:\oracle\odp.net\bin\2.x\Oracle.DataAccess.dll. This allowed me to hit the Oracle DB. But when I take all my files to a clean machine (including the oracle DLL), I get an exception: "The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception." So it seems that it is still depending on some other files. But I don't know what files. And how does it know where the files are? A registry entry? Not looking good for ClickOnce.

Update:

It works as long as I include the files mentioned by mcauthorn: oci.dll, oracle.dataaccess.dll, oraociei11.dll, & oraops11w.dll. U开发者_运维知识库nfortunately, oraociei11.dll is very large -- 114MB.


I would say to go get the ODP.Net Dlls here. You will have to grab the XCopy version, and then add the necessary DLLs to your project and you then should be good to go. The System.Data.OracleClient has been discontinued and is not recommended by Microsoft.


You can use third-party ADO.NET provider. Try this one. It does not require Oracle Client and runs on Mono.


Update, since the original answers are 4 years old.

Just use Oracle's Managed driver. You need only that, nothing else. You can then connect directly with a simple connection string to the database.

<system.data>
  <DbProviderFactories>
    <remove invariant="Oracle.ManagedDataAccess.Client" />
    <!-- If any should be in the machine.config -->
    <add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral" />
  </DbProviderFactories>
</system.data>
<connectionStrings>
  <clear />
  <add name="OracleContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="DATA SOURCE=<IP_ADDRESS>:1521/XE;PASSWORD=<PASSWORD>;USER ID=<USER_ID>;Connection Timeout=600;Validate Connection=true" />
</connectionStrings>

I used ServiceStack's OrmLite as ORM but it should work perfectly fine also directly if you don't want to use an ORM, or with any other. All you need to make sure is that your ORM library is using the managed driver as well and not the old one. I've written a blog post regarding a hack, where I had to change ServiceStack.OrmLite.Oracle to use the new managed driver. This solved all my problems.

  • Blog post: http://peter.grman.at/how-to-connect-mono-in-linux-to-oracle/
  • ServiceStack.OrmLite.Oracle.Managed NuGet package: https://www.nuget.org/packages/ServiceStack.OrmLite.Oracle.Managed/
  • The changes in GitHub: https://github.com/Grman-IT-Solutions/ServiceStack.OrmLite/tree/OracleManagedDataAccess
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号