.NETCore3.0 + EFCore中使用Oracle报“ORA-12154: TNS:could not resolve the connect identifier specified"的错误处理

在.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)))";

posted on 2020-03-08 09:53  fery  阅读(528)  评论(0编辑  收藏  举报