[RESOLVED] Error in Connecting C#.Net with ORACLE
*My tnsNames.Ora File -*
Code:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Sonia-PC)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
*.Net Code -*
Code:
public partial class Default2 : System.Web.UI.Page
{
OracleCommand cmd = new OracleCommand();
OracleConnection conn = new OracleConnection("Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Sonia-PC)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE))),UserID=user_test,Password=sonia;");
protected void Page_Load(object sender, EventArgs e)
{
cmd.CommandText = "INSERTSTUDENT";
cmd.Connection = conn;
cmd.Parameters.Add("p_roll", OracleDbType.Long, 64, 1, ParameterDirection.Input);
cmd.Parameters.Add("p_name", OracleDbType.Varchar2, 2000, "sonia", ParameterDirection.Input);
cmd.Parameters.Add("p_marks", OracleDbType.Long, 64, "10", ParameterDirection.Input);
conn.Open();
cmd.ExecuteNonQuery();
}
}
When the line conn.Open() is executed ERROR is dere - *ORA-12154: TNS:could not resolve the connect identifier specified*
I have set Data Source = XE also but it also giving the same ERROR.
Re: Error in Connecting C#.Net with ORACLE
This is an issue with the way that Oracle is set up. Here's a link for troubleshooting it: http://ora-12154.ora-code.com/
1 think I would check would be the path to your solution. I had an issue where I was working on a project where there was a parenthesis in the folder name. (ex. C:\Users\MattP\Foo\Bar (2)) Removing the parenthesis fixed the problem in that case.
Edit: This article seems to be much more thorough in troubleshooting steps http://edstevensdba.wordpress.com/20...2154tns-03505/
Re: Error in Connecting C#.Net with ORACLE
Hi Mattp.There is no with the Oracle Set up,Because my sql developer and SQL plus too is connected with the oracle without any Error. This error is only while connecting .net + oracle.When I am tried to open connection.
Re: Error in Connecting C#.Net with ORACLE
This question has nothing whatsoever to do with VB.NET, so I'm going to ask the mods to move it to a more appropriate forum.
Re: Error in Connecting C#.Net with ORACLE
Quote:
Originally Posted by
jmcilhinney
This question has nothing whatsoever to do with VB.NET
And I don't think it is related to C# code writing so I'm moving it to Database Development.
Re: Error in Connecting C#.Net with ORACLE
In your connection string, you have a "," (comma) after the user name value. Try replacing that with a ";"(semi-colon).
Your string should now look like this.
PHP Code:
Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Sonia-PC)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE))),UserID=user_test;Password=sonia;"
Re: Error in Connecting C#.Net with ORACLE
Hello abhijit, its done. Replacing the semi-colon with comma worked. BUt there is one change in your answer , we have to replace comma after the Data Source Also : -
Code:
OracleConnection conn = new OracleConnection("Data Source=XE;User Id=user_test;Password=sonia;");
OR
Code:
OracleConnection conn = new OracleConnection("Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = Sonia-PC)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)));User Id=user_test;Password=sonia;");