|
-
Jul 9th, 2012, 09:28 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Jul 9th, 2012, 09:40 AM
#2
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/
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Jul 9th, 2012, 10:55 AM
#3
Thread Starter
Hyperactive Member
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.
-
Jul 9th, 2012, 11:04 AM
#4
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.
-
Jul 9th, 2012, 11:08 AM
#5
Re: Error in Connecting C#.Net with ORACLE
 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.
-
Jul 9th, 2012, 12:50 PM
#6
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;"
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jul 10th, 2012, 12:54 AM
#7
Thread Starter
Hyperactive Member
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;");
Last edited by sonia.sardana; Jul 10th, 2012 at 01:13 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|