1,105,263 Community Members

Problem in connecting database with C#

Member Avatar
MARKAND911
Junior Poster
148 posts since Nov 2008
Reputation Points: -1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

I used following code to connect oracle database from C#.
But i get this error "invalid login credentials"

using (Oracle.DataAccess.Client.OracleConnection cn = new Oracle.DataAccess.Client.OracleConnection("Data Source=abcSource;User Id=abcUserId;Password=abcPassword;") 
{ 
    cn.Open(); 
}

While if i try following code to connect database from C# I succeed.

using (System.Data.OracleClient.OracleConnection cn = new System.Data.OracleClient.OracleConnection("Data Source=abcSource;User Id=abcUserId;Password=abcPassword;"));  
{  
   cn.Open();  
}

I dont understand, what is happening
Please! Can anyone help me

Member Avatar
ChrisHunter
Practically a Master Poster
625 posts since Feb 2011
Reputation Points: 120 [?]
Q&As Helped to Solve: 69 [?]
Skill Endorsements: 15 [?]
Featured
 
0
 

The source should be the name of the server the DB is on and the catalog should be the name of the database so try adding a catalog attribute to the connection string just after the source attribute.

EDIT: Sorry my advice is for an SQL server database and not an Oricale DB.

Member Avatar
RvSon
Junior Poster in Training
72 posts since Aug 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
1
 

Hi,

In first method you have not closed ')' properly. you are missing one Close')' at the end of query and also missing ';'.

And

  I think you should try this as well.



     using System;
        using System.Data;
        using Oracle.DataAccess.Client; 

        class ConnectionSample
        {
          static void Main()
          {  
            string connstr = "User Id=ID;Password=Pass;Data Source=SourceName";
            OracleConnection con = new OracleConnection(connstr);
            con.Open();
          }
        }   

Hope it will Work for you.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: