问题
I create a simple Win Form application. However I am getting the error: ORA-12154: TNS:could not resolve the connect identifier specified
I have an Oracle connection setup. I verified this by connecting to the database via the Server Explorer. (Connect to DB).
I know it's something trivial that I'm missing.
I am using Oracle Managed Driver that I downloaded from Nuget.
I suspect it can't find my TNS setting. How do I verify that?
Simple code:
string connString = "Data Source=qqqqq;User Id=zzzzzz;Password=xxxxx;";
using (OracleConnection oConn = new OracleConnection(connString))
{
oConn.Open();
OracleCommand cmd = new OracleCommand("select * from my_table");
var recCount = cmd.ExecuteNonQuery();
}
回答1:
Most likely the ODP.Net Managed Driver does not find your tnsnames.ora file, resp. ldap.ora file in case of Oracle names service
Search path for tnsnames.ora file is this:
- data source alias in the
dataSourcessection under<oracle.manageddataaccess.client>section in the .NET config file (i.e.machine.config,web.config,user.config). - data source alias in the
tnsnames.orafile at the location specified byTNS_ADMINin the .NET config file. Locations can consist of either absolute or relative directory paths. - data source alias in the
tnsnames.orafile present in the same directory as the.exe.
See Oracle Data Provider for .NET, Managed Driver Configuration
Note, unlike ODP.NET unmanaged driver, SQL*Plus or tnsping.exe tool the ODP.Net Managed Driver does not read Environment variable TNS_ADMIN nor registry key HKLM\SOFTWARE\ORACLE\KEY_{Oracle-Home}\TNS_ADMIN
来源:https://stackoverflow.com/questions/41571522/win-form-ora-12154-tnscould-not-resolve-the-connect-identifier-specified