.NETCore3.0 + EFCore中使用Oracle报“ORA-12154: TNS:could not resolve the connect identifier specified&quo

在.NETCore3.0 + EFCore中的Oracle连接串的Data Source如果直接用TNS NAME会报“ORA-12154: TNS:could not resolve the connect identifier specified”

//eg:

optionsBuilder.UseOracle(@"User Id=<USER>;Password=<PASSWORD>;Data Source=<TNS NAME>") ;
假设上述TNS NAME=ORCL

//解决办法是上面代码前追加:
方案1:直接设置TnsAdmin路径

// Set TnsAdmin value to directory location of tnsnames.ora and sqlnet.ora files
OracleConfiguration.TnsAdmin = @"<DIRECTORY LOCATION>";


方案2:单独设置Tns Name(两种方式)

// Add data source through Add method on OracleDataSourceCollection
OracleConfiguration.OracleDataSources.Add("ORCL", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname>)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))");

// Add data source through indexer method on OracleDataSourceCollection
OracleConfiguration.OracleDataSources["ORCL"] = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname>)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))";

上一篇:几种关系型数据库比较


下一篇:12 oracle 数据库坏块--物理坏块-ORA-01578/ORA-01110