C# 从ASP.NET连接到Oracle不符合预期

C# 从ASP.NET连接到Oracle不符合预期,c#,asp.net,oracle,database-connection,C#,Asp.net,Oracle,Database Connection,我犯了一个令人沮丧的错误。我正在从Winforms应用程序和Asp.net页面连接到Oracle(或尝试连接)。 Winforms-没问题,Asp.Net-有很多问题 我得到的错误(从IIS运行)是: 对我来说,这条消息可能表明我的连接字符串错误,或者Oracle关闭,或者防火墙问题,但我使用的连接字符串和代码与同一台机器上的Winforms相同 有没有其他可能导致此错误的想法 失败的代码: string conn = "User Id=172.xx.xx.xxx ;Password=xxx;D

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

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

对我来说,这条消息可能表明我的连接字符串错误,或者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客户端文件夹)->产品->网络->管理->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.
确保
地址
参数输入正确;最可能不正确的参数是节点名。确保服务器的可执行文件存在。如果协议是TCP/IP,请编辑TNSNAMES.ORA文件,将主机名更改为数字IP地址,然后重试

最后,再次检查您的连接字符串。例如,当使用asp.net时,其格式如下所示。(Web.config示例)


详细解释。

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


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

显示堆栈跟踪我没有访问Oracle服务器的权限,但是如果这些建议中有任何一个出现错误,那么我从Winforms应用程序的连接肯定也会失败?请再次检查连接字符串中的地址参数。虽然这不是一个坏主意,不利的一面是,我必须将Oracle客户端部署到将要部署它的所有服务器上。不过我会试试这个。
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.
<add name="OracleConnectionString"
  connectionString="Data Source=OracleServer1;Persist 
    Security Info=True;Password="******";User ID=User1"
  providerName="System.Data.OracleClient" />