ODAC 和C# - TNS:发生连接超时 - 仅通过 VS2005 调试器连接

发布于 2024-09-10 17:52:28 字数 2238 浏览 9 评论 0原文

我是 Oracle 新手,我面临一个问题。当我从 IDE - Visual Studio 2005 运行该应用程序时,数据库连接顺利建立,但是当我运行该应用程序的已安装版本时,数据库连接失败,并出现 TNS:发生连接超时错误。

我尝试使用 SQLNET.ORA 和网上找到的类似解决方案,但无法解决问题。我想知道为什么会发生这种情况,因为通过 IDE 运行的应用程序和通过安装运行的应用程序位于同一台 PC 上。我确保 TNSNAMES.ORA 文件已正确编辑,并且我可以通过直接在 Visual Studio 上运行的应用程序实例进行连接。

public bool connectToDatabase(string dbConnStr)
{
    try
    {
        databaseConnection = dbConnStr;
        OracleConnection dbConn = new OracleConnection(databaseConnection);
        if (dbConn == null)
        {
            CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "Connection object is null");
            return false;
        }
        if (dbConn.State.ToString().Equals("Closed", StringComparison.OrdinalIgnoreCase))
        {
            CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "DB connection - " + dbConn.ConnectionString);
            dbConn.Open();
            return true;
        }
    }
    catch (Exception ex)
    {
        CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, ex.Message + "\n" + ex.StackTrace);
        CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "DB String - " + databaseConnection);

        return false;
    }
    return false;
}

堆栈跟踪如下所示:

7/22/2010 6:38:51 PM    ORA-12170: TNS:Connect timeout occurred
   at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
   at Oracle.DataAccess.Client.OracleConnection.Open()
   at SQL.connectToDatabase(String dbConnStr)

tnsnames.ora 是这样的:

MySource =
  (DESCRIPTION =
    (CONNECT_TIMEOUT=180)(RETRY_COUNT=2)
    (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 125.63.77.232)(PORT = 1521)))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = MySource )
    )
  )

与此同时,我通过调试器发出了 ContextSwitchDeadlock 错误,因此我按照说明将 Main() 上的属性从 STAThread 更改为 MTAThread。不再有 ContextSwitchDeadlock - 但连接问题仍然存在。

我希望你能对这个问题有所了解——我快要抓狂了。任何见解将不胜感激。

I am new to Oracle, and there is an issue I am facing. When I run the application from IDE - Visual Studio 2005, The database connection is established smoothly, but when I run an installed version of the app, the DB connection fails and I get a TNS: Connect timeout occurred error.

I tried with SQLNET.ORA and similar solutions found online, but I could not resolve the issue. I wonder why this happens, since the application running through the IDE and through an installation is on the same PC. I made sure the TNSNAMES.ORA file was correctly edited, and I can connect through an instance of the application running directly on Visual Studio.

public bool connectToDatabase(string dbConnStr)
{
    try
    {
        databaseConnection = dbConnStr;
        OracleConnection dbConn = new OracleConnection(databaseConnection);
        if (dbConn == null)
        {
            CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "Connection object is null");
            return false;
        }
        if (dbConn.State.ToString().Equals("Closed", StringComparison.OrdinalIgnoreCase))
        {
            CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "DB connection - " + dbConn.ConnectionString);
            dbConn.Open();
            return true;
        }
    }
    catch (Exception ex)
    {
        CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, ex.Message + "\n" + ex.StackTrace);
        CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "DB String - " + databaseConnection);

        return false;
    }
    return false;
}

The stack trace reads like this:

7/22/2010 6:38:51 PM    ORA-12170: TNS:Connect timeout occurred
   at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
   at Oracle.DataAccess.Client.OracleConnection.Open()
   at SQL.connectToDatabase(String dbConnStr)

The tnsnames.ora is something like this:

MySource =
  (DESCRIPTION =
    (CONNECT_TIMEOUT=180)(RETRY_COUNT=2)
    (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 125.63.77.232)(PORT = 1521)))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = MySource )
    )
  )

In the meanwhile, I was being issued a ContextSwitchDeadlock error through the debugger, so I followed instructions and changed the attribute from STAThread to MTAThread on Main(). No more ContextSwitchDeadlock - and Still, the connection issue persists.

I was hoping you could shed some light on the issue - I am close to pulling my hair out. Any insight would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2024-09-17 17:52:28

问题已解决。非常感谢大家的帮助! :) 结果是损坏的 ODAC dll 的组合以及其他一些。

Issue was resolved. Thank you very much for your help, everyone! :) Turned out to be a combination of corrupted ODAC dll's and then some.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文