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.

Re: Occasional error opening a connection by Sahil

Sahil
Thu Sep 30 00:13:09 CDT 2004

Is your tnsnames.ora file allright?

--

- Sahil Malik
You can reach me thru my blog -
http://www.dotnetjunkies.com/weblog/sahilmalik

"Roger Sutter" <Roger Sutter@discussions.microsoft.com> wrote in message
news:A88B9D9E-2798-419F-AE0A-982BFA82DDE1@microsoft.com...
> 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.
>



Re: Occasional error opening a connection by Miha

Miha
Thu Sep 30 01:33:38 CDT 2004

Hi Roger,

I would guess that it is oracle or network related problem.
Did you try using native provider?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Roger Sutter" <Roger Sutter@discussions.microsoft.com> wrote in message
news:A88B9D9E-2798-419F-AE0A-982BFA82DDE1@microsoft.com...
> 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.
>



RE: Occasional error opening a connection by DavidSwanson

DavidSwanson
Fri Feb 18 09:49:12 CST 2005

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!

"Roger Sutter" wrote:

> 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.
>

RE: Occasional error opening a connection by Stephen

Stephen
Fri Aug 18 10:22:07 CDT 2006

Hey Roger
did u fix the error? i have the same proble

From http://www.developmentnow.com/g/7_2004_9_0_0_133588/Occasional-error-opening-a-connection.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com