我是linux ubuntu和mono运行时的新手我尝试连接到oracle 11G,就像通常在windows 中一样(我在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;
答案 0 :(得分:0)
您需要安装OCI,per the documentation。另外,请记住不再支持Oracle Data Client(在Mono和Microsoft .NET中),所以最安全的选择是use a commercial provider。你已经为这个数据库支付了几笔资金,几百个人有什么不同?
答案 1 :(得分: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库也使用托管驱动程序而不是旧驱动程序。我写了一篇关于黑客的博客文章,我不得不更改ServiceStack.OrmLite.Oracle以使用新的托管驱动程序。这解决了我所有的问题。