I have a C# ASP.NET application which connects to an Oracle db. When i access the site via
http://localhost/mysite/ it works fine, but if I enter the site using debug mode in Visual Studio 2008 I get the error 'ORA-12154: TNS:could not resolve the connect identifier specified'.
The only solutions I can find around this error is the check the tnsnames.ora file - but i'm not sure what i should be checking as it work fine when not in debug mode! Where am I going wrong? Is this something to do with 32/64bit issue?
///<summary> ///
Get the data from the database in the form of a OracleDataReader. ///</summary> ///<param name="connectionName">Connection
to use</param> ///<returns>OracleDataReader
containing the data.</returns>
BoxheadMonke...
Member
37 Points
36 Posts
ASP.NET oracle connection not working in debug mode
May 01, 2012 04:27 PM|LINK
I have a C# ASP.NET application which connects to an Oracle db. When i access the site via http://localhost/mysite/ it works fine, but if I enter the site using debug mode in Visual Studio 2008 I get the error 'ORA-12154: TNS:could not resolve the connect identifier specified'.
The only solutions I can find around this error is the check the tnsnames.ora file - but i'm not sure what i should be checking as it work fine when not in debug mode! Where am I going wrong? Is this something to do with 32/64bit issue?
cheers
ruipedromach...
Member
258 Points
84 Posts
Re: ASP.NET oracle connection not working in debug mode
May 02, 2012 07:31 AM|LINK
hi,
im not sure how you are connecting to oracle ....
what i do is, in my connection string i use the entire block from tnsnames file. this way im never dependent on the oracle configuration.
all you have to do is make sure you have oracle client well installed.
here it goes
using system.data.oracleclient; oracleconnection a = new oracleconnection(); a.connectionstring = "User ID=" + /*your_oracle_user*/ + ";Password=" + /*your_oracle_password*/ + ";Data Source=" + "(DESCRIPTION = " + " (ADDRESS = (PROTOCOL = TCP)(HOST = " + /*Your_host_name_or_ipaddress*/ + ")(PORT = 1521)) " + " (CONNECT_DATA = " + " (SERVER = DEDICATED) " + " (SID = " + /*Your_Sid_NAME*/ + ") " + " ) " + ")"; a.open();BoxheadMonke...
Member
37 Points
36 Posts
Re: ASP.NET oracle connection not working in debug mode
May 02, 2012 10:35 AM|LINK
Not sure that helps as we use a dataaccesslayer class:
Call:
DataAccessLayer.GetOracleDataReader("SELECT * FROM Table", DataAccessLayer.DatabaseConnections.MyConnectionName))
Class:
(DatabaseConnections is an Enum used to access the connection string from the web.config)
public static OracleCommand CreateOracleCommand(string queryString, DatabaseConnections connectionName)
{
OracleConnection oracleCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings[connectionName.ToString()].ConnectionString);
OracleCommand oracleCmd = new OracleCommand(queryString, oracleCon);
oracleCmd.CommandType = CommandType.Text;
oracleCmd.CommandTimeout = 900;
return oracleCmd;
}
/// <summary>
/// Get the data from the database in the form of a OracleDataReader.
/// </summary>
/// <param name="connectionName">Connection to use</param>
/// <returns>OracleDataReader containing the data.</returns>
public static OracleDataReader GetOracleDataReader(string queryString, DatabaseConnections connectionName)
{
//Create the command.
using (OracleCommand oracleCmd = DataAccessLayer.CreateOracleCommand(queryString, connectionName))
{
//Open the connection.
oracleCmd.Connection.Open();
//Return a datareader of the data. CommandBehaviour.Closeconnection will force
//the Oracle connection to be closed when the reader is closed.
return oracleCmd.ExecuteReader(CommandBehavior.CloseConnection);
}
}
ruipedromach...
Member
258 Points
84 Posts
Re: ASP.NET oracle connection not working in debug mode
May 02, 2012 04:15 PM|LINK
yeps
samething just add the conenctionstring to your web.config file
BoxheadMonke...
Member
37 Points
36 Posts
Re: ASP.NET oracle connection not working in debug mode
May 03, 2012 02:32 PM|LINK
OK - done that, same issue! Ihave read this:
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/cd533acd-590f-4644-b753-e31e7019e567
However I cannot do this as the 'web tab' it refers to is not present on my project!