Results 1 to 7 of 7

Thread: [RESOLVED] Error in Connecting C#.Net with ORACLE

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

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

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Error in Connecting C#.Net with ORACLE

    Quote Originally Posted by jmcilhinney View Post
    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.

  6. #6
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    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
  •  



Click Here to Expand Forum to Full Width