TNS 12154 error while connecting from VS2005

irfi

Member
Joined
Sep 24, 2009
Messages
16
Programming Experience
1-3
Hi everyone,
I have installed odp.net and succesfully connect to the oracle 10g database using the VS 2005 from windows form setting property. I mean when i click Test Connection it succeeds. An "app.config" is automatically created.

Now the problem i am facing is that when i try to retrieve the connection string from the app.config on my windows form with the following code i get "ORA 12154 TNS Error:"could not resolve the connect identifier".


Dim cn As New OracleConnection
cn.ConnectionString = getConnectionString()


Private Function getConnectionString() As String
Dim cnBuilder As New OracleConnectionStringBuilder
With cnBuilder
.DataSource = My.Settings.OraCon
.UserID = My.Settings.OraCOn
.Password = My.Settings.OraCOn
End With
Return cnBuilder.ConnectionString
End Function


I have copied the TNSNAMES.ORA file from the Oracle 10g Server and placed it into the following path:
C:\Oracle\product\10.2.0\client_1\NETWORK\ADMIN\

My TNSNAMES.ORA ENTRY Looks like this:

# tnsnames.ora Network Configuration File: C:\oracle\product\10.1.0\Db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oraserver)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)


The SQLNET.ORA file looks like this:

# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.

SQLNET.AUTHENTICATION_SERVICES= (NTS)


I did TNSPING ORCL throught the Command Prompt and get the following results:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>tnsping orcl

TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 - Production on 24
2009 21:45:32

Copyright (c) 1997, 2005, Oracle. All rights reserved.

C:\oracle\product\10.2.0\client_1\network\admin\sqlnet.ora


Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oraserver)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))

Does anyone know what could be the likely cause of this error.

Much appreciated

Thanx and Cheers
irfi
 
You're using .net 2.0 - why would you be looking in app.config?

To use an oracle database, do this:

Put a new dataset in your project
Add a TableAdapter
A box appears asking for connection options
Choose database
Design the connection string (the thing where you say your test connection succeeds)
Advance through the wizard
Put in a query like SELECT * FROM dual
Finish the wizard

Now you have: a tableadapter, a datatable

To use this in your project, show the Data Sources window (its on one of the menus). You can see in there the DUAL table you just "linked" to (its not the table, but a local representation of it

Read the DW2 link in my signature, section Creating a Simple Data App - the point where your knowledge and the microsoft sql server example cross over should be obvious
 
Thank you for your reply,

My problem is getting connection to the database from my login screen. I get the error "ORA 12154 TNS Error:"could not resolve the connect identifier"

But in the design mode of the form when i go the properties of the form and define a connection string for example:
Name: Oraconnection
Type: Connection String
Scope: Application
And when i click to open the connection properties window i choose
Oracle Database(Oracleclient)
Server name: orcl
Username: xyz
Password: abc

Test Connection: "Connection Succeeded"

And as i explained in my previous post that when i retrieve this from app.config i get the above error TNS 12154 error

From the login screen I need to authenticate the users against the (user_table) in the database... so for that i must have a proper connection string.

I am sure once connected i can manipulate data though DataAdapter etc.

Lastly when i harcode the connection string which i dont want to due to sensitive information... it works fine!!

cn.ConnectionString = _
"Data Source=orcl" & ";" & "User Id=xyz" & ";" & "Password=abc"


In App.Config there are ways to encrypt the sonnection string.

Any more suggestions or a better approach.
Thanx
irfi
 
so youre retrieving it yourself manually?

Most winforms apps have settings.settings, not app.config and that's where the connections strings live and are pulled automatically by the tableadapter in use

If youre retrievng it manually and it's broken, yet you can hardcod eand it works, first thing I'd do is compare the two ina debugger - the connstr youre retrieving manually will be damaged or broken
 
Back
Top