Win Form: ORA-12154: TNS:could not resolve the connect identifier specified

瘦欲@ 提交于 2021-01-29 03:23:51

问题


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:

  1. data source alias in the dataSources section under <oracle.manageddataaccess.client> section in the .NET config file (i.e. machine.config, web.config, user.config).
  2. data source alias in the tnsnames.ora file at the location specified by TNS_ADMIN in the .NET config file. Locations can consist of either absolute or relative directory paths.
  3. data source alias in the tnsnames.ora file 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!