2

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.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Sreedevi J
  • 673
  • 1
  • 9
  • 15
  • Have you ensured that your application (when installed) has at least `Read` rights to the various Oracle client files and that file/registry virtualisation is not interfering? Have you also ensured that there is no firewall blocking outgoing traffic on the port the Oracle service is running on? – slugster Jul 21 '10 at 10:55
  • Yes, it has read access; there is no firewall blocking any ports either. Had that checked out first thing. I'm still wondering why it works only when running on VS2005 IDE - the application works like a charm at that point. – Sreedevi J Jul 21 '10 at 11:01
  • Also, if I use SQLNET.ORA, I get a "packet write failure" error and it fails to connect from both instances - debugger and installed. IS that offering any clues? For now I am not using the SQLNET.ORA file. – Sreedevi J Jul 22 '10 at 06:00

1 Answers1

0

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.

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
Sreedevi J
  • 673
  • 1
  • 9
  • 15