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.