Occasional error opening a connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using VS.Net 2003 and C# to write an app that connects to an Oracle 9i
database. I have a button on a form that takes username/password/service
name information, creates a connection string and issues an open command.
From time-to-time, I get an error "ora-12154 tns:could not resolve service
name". The problem is that it doesn't happen all the time. Any idea's about
what may be going on?

Here's my code:


//Create a string builder to put together the connection string from the
user input
// Provider=MSDAORA.1;UserID=xx;Password=xx;Data Source=dev9
StringBuilder sb = new StringBuilder();

sb.Append("Provider=MSDAORA.1;User ID=");
sb.Append(txtUserName.Text);
sb.Append(";Password=");
sb.Append(txtPassword.Text);
sb.Append(";Data Source=");
sb.Append(txtDatabase.Text);


try
{
//Create connection object using the connection string
connString = sb.ToString();
oConnection1 = new OleDbConnection(connString);

oConnection1.Open(); <==== this line sometimes generates an error

//check to make sure the connection was opened
if (oConnection1.State == ConnectionState.Open)
{
//write a status to the display
rtbConnect.AppendText("Opened connection \n");
rtbConnect.Refresh();
...



I'm really perplexed why the open command generates an error from
time-to-time.
The connection string seems to be correct. I can paste it into a test.udl
file and it always works. dev9 is declared in my tnsnames.ora file and I
have no problems creating ODBC connections using it.
 
Hi Roger,

I would guess that it is oracle or network related problem.
Did you try using native provider?
 
Roger, Did you ever resolve this issue? I have the exact same thing using
the System.Data.OracleClient. Random ora-12154 tns:could not resolve service
name errors.

Very frustrating!
 
Back
Top