question

programinca-9868 avatar image
0 Votes"
programinca-9868 asked SaurabhSharma-msft edited

Error connecting Oracle with c#

Hi everyone. I have an issue trying to connect Oracle with C#, I hope you can helpme.
I’m using Oracle SQL Developer and make the connection successfully:


141774-f1.png


Everything Works fine:

141755-f2.png




But then, when I’m trying to connect to that database from C#, I get an error:


 using System.Data.OracleClient;
    
 DataTable dtResult = new DataTable();            
                
 string cnnString2 = @"Data Source=xe; USER ID=system; PASSWORD=admin;";
    
 using (OracleConnection cnn = new OracleConnection(cnnString2))
 {
     OracleCommand cmd = new OracleCommand( @"SELECT * FROM TABLE");
    
     cmd.CommandType = CommandType.Text;
    
     OracleDataAdapter da = new OracleDataAdapter(cmd);
    
     cnn.Open();
    
     da.Fill(dtResult);
    
     cnn.Close();            
 }
    
 return dtResult;


In the cnn.Open line, I get this error:

System.Data.OracleClient.OracleException: 'ORA-12154: TNS:could not resolve the connect identifier specified


I tried this same code in my personal laptop, and works ok, but I’m using now a Laptop from my company, and I get that error. The strange thing is that I can connect from the soft Oracle SQL Developer, but from C# nope. Anyone have some solution for this?

Thanks in advance.



dotnet-csharpdotnet-visual-basicazure-database-migration
f1.png (49.3 KiB)
f2.png (4.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

karenpayneoregon avatar image
1 Vote"
karenpayneoregon answered

Try Persist Security Info=True;

Data Source=TODO;Persist Security Info=True;Enlist=false;Pooling=true;Statement Cache Size=10;User ID=TODO;Password=TODO;

This comes from porting a connection string from SQL-Developer (or Toad)

141843-figure1.png



figure1.png (15.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.