1

我是 linux ubuntu 和单声道运行时的新手,我尝试像通常在 windows 中那样连接到 oracle 11G (我在 windows 中尝试了 System.Data.OracleClient 和 Oracle.OracleClient 并且都运行良好) 但我在 ubuntu 中遇到了这个问题: System.DllNotFoundException: libclntsh.so 这是堆栈跟踪:

    libclntsh.so

Description: HTTP 500. Error processing request.

Stack Trace:

System.DllNotFoundException: libclntsh.so
  at (wrapper managed-to-native) System.Data.OracleClient.Oci.OciCalls/OciNativeCalls:OCIEnvCreate (intptr&,System.Data.OracleClient.Oci.OciEnvironmentMode,intptr,intptr,intptr,intptr,int,intptr)
  at System.Data.OracleClient.Oci.OciCalls.OCIEnvCreate (System.IntPtr& envhpp, OciEnvironmentMode mode, IntPtr ctxp, IntPtr malocfp, IntPtr ralocfp, IntPtr mfreep, Int32 xtramem_sz, IntPtr usrmempp) [0x00000] in <filename unknown>:0 
  at System.Data.OracleClient.Oci.OciEnvironmentHandle..ctor (OciEnvironmentMode mode) [0x00000] in <filename unknown>:0 
  at System.Data.OracleClient.Oci.OciGlue.CreateConnection (OracleConnectionInfo conInfo) [0x00000] in <filename unknown>:0 
  at System.Data.OracleClient.OracleConnectionPoolManager.CreateConnection (OracleConnectionInfo info) [0x00000] in <filename unknown>:0 
  at System.Data.OracleClient.OracleConnectionPool.CreateConnection () [0x00000] in <filename unknown>:0 
  at System.Data.OracleClient.OracleConnectionPool.GetConnection () [0x00000] in <filename unknown>:0 
  at System.Data.OracleClient.OracleConnection.Open () [0x00000] in <filename unknown>:0 
  at example.Default.button1Clicked (System.Object sender, System.EventArgs args) [0x0000d] in /home/danar/Projects/example/example/Default.aspx.cs:18 
  at System.Web.UI.WebControls.Button.OnClick (System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.Web.UI.WebControls.Button.RaisePostBackEvent (System.String eventArgument) [0x00000] in <filename unknown>:0 
  at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (System.String eventArgument) [0x00000] in <filename unknown>:0 
  at System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler sourceControl, System.String eventArgument) [0x00000] in <filename unknown>:0 
  at System.Web.UI.Page.RaisePostBackEvents () [0x00000] in <filename unknown>:0 
  at System.Web.UI.Page.ProcessRaiseEvents () [0x00000] in <filename unknown>:0 
  at System.Web.UI.Page.InternalProcessRequest () [0x00000] in <filename unknown>:0 
  at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0

这是我到 oracle 的连接字符串,我使用了 System.data.oracleclient

string oradb = "Data Source=(DESCRIPTION="
                        + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))"
                        + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));"
                        + "User Id=hr;Password=hr;";
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();
            OracleCommand command=new OracleCommand();
            command.Connection=conn;
            command.CommandText="select * from employee";
            OracleDataReader reader=command.ExecuteReader();
            while(reader.Read())
            {
                Response.Write(reader[0]+"<br>");
            }
            conn.Close();
            command=null;
            reader.Close();
            reader=null;
4

2 回答 2

0

更新,因为原来的答案是 2 岁。

只需使用 Oracle 的托管驱动程序。你只需要那个,没有别的。然后,您可以使用简单的连接字符串直接连接到数据库。

<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>

我使用 ServiceStack 的 OrmLite 作为 ORM,但如果您不想使用 ORM 或其他任何 ORM,它也可以直接正常工作。您只需要确保您的 ORM 库也在使用托管驱动程序,而不是旧驱动程序。我写了一篇关于 hack 的博客文章,我不得不更改 ServiceStack.OrmLite.Oracle 以使用新的托管驱动程序。这解决了我所有的问题。

于 2014-09-03T23:47:42.720 回答
0

根据文档,您需要安装OCI。另外,请记住,不再支持 Oracle 数据客户端(在 Mono 和 Microsoft .NET 中),因此您最安全的选择是使用商业提供商。你已经为数据库支付了好几美元,几百美元有什么区别?

于 2012-09-17T20:30:32.440 回答