We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,756 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

connection status closed after opening c# oracle

Hi

I am getting weird error with oracle connectivity. Immediately after the open() call, the connection shows as closed. I am not able to figure out whats going wrong. The same code works if executed differently.

Line:

This piece of code throws error

bool objState = false;
    if (Program.orConn == null)
    {
      objState = true;
    }
    else if (Program.orConn.State == ConnectionState.Closed)
    {
      objState = true;
    }
    if(objState)
    using (Program.orConn = new OracleConnection("Data Source=" + Program.dSource + ";" +
    "User id=" + Program.dUser + ";" +
    "Password=" + Program.dPass + ";"))
    {
      try
      {
        Program.orConn.Open();
      }
      catch(Exception ex)
      {
        System.Console.WriteLine(ex.ToString());
      }
    }
    string singleRecQry = "SELECT REPORT_ID FROM USERREPORT WHERE ROWNUM=1 AND STATUS='INQUEUE' ORDER BY REPORT_ID ASC";
    .
    .
    .

Error Dump:

System.Data.OracleClient.OracleException: ORA-12170: TNS:Connect timeout occurred

at System.Data.OracleClient.OracleException.Check(OciErrorHandle errorHandle, Int32 rc)
at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OracleClient.OracleConnection.Open()
at PresentationGenerator.Program.openConnectDB() in C:\Documents and Settings\vedp\My Documents\Visual Studio 2008\Projects\MyConsoleApplication\MyConsoleApplication\Program.cs:line 123

Line:

This Works

try
      {
          
          using (Program.orConn = new OracleConnection("Data Source=" + Program.dSource + ";" +
              "User id=" + Program.dUser + ";" +
              "Password=" + Program.dPass + ";"))
          {
              Program.orConn.Open();
              string singleRecQry = "SELECT REPORT_ID FROM USERREPORT WHERE ROWNUM=1 AND STATUS='INQUEUE' ORDER BY REPORT_ID ASC";
              OracleCommand orCmd = new OracleCommand(singleRecQry, Program.orConn);
              orCmd.CommandType = CommandType.Text;
              OracleDataReader orDatRdr = orCmd.ExecuteReader();
              orDatRdr.Read();
        .
        .
        .
        }
      }
      catch(Exception ex)
      {
        System.console.writeLine(ex.toString());
      }

Can anyone tell me the reason for this to behave this way?

Thanks,

Ved

Disclaimer: this question has been posted on OTN forum also. Didn't receive any reply so posting it here. Apologies in advance to the forum members if this offends in anyway.

1
Contributor
1
Reply
23 Hours
Discussion Span
3 Years Ago
Last Updated
2
Views
nirvana74v
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hi All,

I guess there was some network issue, when I moved my code to my colo servers it worked fine.

Thanks,

Ved

nirvana74v
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0724 seconds using 2.68MB