繁体   English   中英

无法从ASP.NET连接到Oracle

[英]Connect to Oracle from ASP.NET not as expected

我有一个令人沮丧的错误。 我正在同时从Winforms应用程序和Asp.net页面连接到Oracle(或试图连接到Oracle)。
Winforms-没问题,Asp.Net-有很多问题。

我得到的错误(从IIS运行)是:

ORA-12545: Connect failed because target host or object does not exist

对我来说,此消息可能表明我的连接字符串错误或Oracle已关闭,或者防火墙出现问题,但是我使用的是同一台计算机上Winforms上的相同连接字符串和代码。

任何想法其他想法可能导致此错误?

失败的代码:

string conn = "User Id=172.xx.xx.xxx ;Password=xxx;Data Source=(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=xx)(PORT=1521)) (CONNECT_DATA=(SID=xxx))); 
OracleConnection oc = new OracleConnection(conn);

编辑:
全栈:

ORA-12545: Connect failed because target host or object does not exist 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

     Exception Details: Oracle.DataAccess.Client.OracleException: ORA-12545: Connect failed because target host or object does not exist

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[OracleException (0x80004005): ORA-12545: Connect failed because target host or object does not exist]
   Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck) +1563
   Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src) +59
   Oracle.DataAccess.Client.OracleConnection.Open() +4899
   UDWWeb.Pages.Availability.Button1_Click(Object sender, EventArgs e) +49
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

而不是在数据源中提供Tns。 将其放入(Oracle Client Folder)->产品->网络-> admin-> tnsnames.ora文件。

然后,您可以像使用Sql数据源一样使用OleDbConnection。 例如:

Provider=OraOLEDB.Oracle.1;Password=***;Persist Security Info=True;User ID=***;Data Source=DataSource_Name_in_TNS_File

首先,执行以下检查:

1.) making sure that your listener is running (lsnrcrl stat)
2.) testing connectivity with ping, and then tnsping.
3.) verifying connectivity via the DNS (e.g. /etc/hosts)
4.) make sure to check your tnsnames.ora parms.

确保正确输入了ADDRESS参数; 最有可能不正确的参数是节点名称。 确保服务器可执行文件存在。 如果协议是TCP / IP,请编辑TNSNAMES.ORA文件以将主机名更改为数字IP地址,然后重试。

最后,再次检查您的ConnectionString。 例如,当使用asp.net时,它的格式如下所示。(Web.config示例)

<add name="OracleConnectionString"
  connectionString="Data Source=OracleServer1;Persist 
    Security Info=True;Password="******";User ID=User1"
  providerName="System.Data.OracleClient" /> 

检查此详细说明。

我也遇到了同样的问题,该应用程序正在本地PC上运行,但是当我将其上传到服务器时,却遇到了同样的错误。

我只需在连接字符串中写入完整的主机名即可解决此问题,例如host=abcd.exchange.com 不要写一个简短的名字,例如host=abcd

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM