1.11M Members

Problem in connecting database with C#

 
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

 
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.

 
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 six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: