Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

The code for the connect function is as below. I am able to connect fine when I run through VS2005 [F5] but not when I install the same code as an executable. So far I have tried and failed to resolve it. Any insight would be appreciated, I am out of ideas and fast running out of time. :((

C#
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 is as below:

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 file is as below, although since I can connect from Visual Studio, I can safely say that this is correctly edited.

VB
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 )
    )
  )


Any help is appreciated. Thanks in advance.

-Sreedevi.
Posted

1 solution

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

Cheers!
 
Share this answer
 
Comments
giridasmart1 5-Jan-14 13:10pm    
Hi,

Could you please pass on how you resolved this issue; Am facing the similar issue with .NET 2012 with 4.5 framework;
In VS 2012 its working fine and when deployed to IIS web server throwing TNS time out error; Rest of the websites using the same DLL and are working fine. Your help would be much appreciated;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900