Reputation: 1
Hi I'm in quite a tough situation for my work, I'm trying to access my works Oracle SQL database programmatically to retrieve info. The connection is open and I'm able to view the session in Oracle SQL DEVELOPER, using V$SESSION
, but when I try to send a query or read the result the remotehost terminates the connection.
Im using C# and I am using the ManagerDataAcess library because the database is quite old, running Oracle SQL 10, and it's the only library I've found so far that allows me to specify the SID and actually let me connect to the DB.
The variable connection
is of type OracleConnection
I then assign a query to a string
String query = "SELECT note FROM TABLE_NAME WHERE..."
Then I create a command
OracleCommand cmd = new Oracle command(query, connection);
Create a reader then execute it
OracleDataReader reader = cmd.ExecuteReader();
At this point and all points before the property connection.State
returns the value "Open"
But as soon as I call reader.Read()
the connection closes, the exact error varies but the most common ones are ORA-12570 and ORA-03135, which tell me almost nothing except that the remote host terminated the connection
I assume that this has something to do with the DB being so old.
Any ideas or expertise would be greatly appreciated. Thank you.
Also if anyone is wondering my work is planning on replacing it, but not for another 9 months.
I made sure that the connection string was correct.
Attached is a somewhat simplified version of the code
private void Initialize()
{
string connectionString = "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =[hostname])(PORT =[port]))(CONNECT_DATA =(SID =[sid]))); User Id =[login]; Password =[password];"
try
{
connection = new OracleConnection();
connection.ConnectionString = connectionString;
connection.Open();
MessageBox.Show(connection.State.ToString());
connection.Close();
}
catch (Oracle.ManagedDataAccess.Client.OracleException ex)
{
MessageBox.Show(ex.Message);
}
}
public string Select()
{
string query = "SELECT NOTE FROM [TableName] WHERE [cond]";
//Create a list to store the result
string note;
//at this point the connection is closed
//Open connection
if (this.OpenConnection() == true) //here the connection is open
{
//Create Command
OracleCommand cmd = new OracleCommand(query, connection);
//Create a data reader and Execute the command
OracleDataReader reader;
MessageBox.Show(cmd.CommandText);
reader = cmd.ExecuteReader();
//right here the connection is still open
//Read the data and store them in the list
if (reader.Read())//right here is where the exception is thrown and the connection is closed
{
note = reader["NOTE"] + "";
}
else
{
}
//close Data Reader
reader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return note;
}
else
{
return "";
}
}
Upvotes: 0
Views: 35