本地 IIS 上的 Oracle ORA-12154 错误,但 Visual Studio 开发服务器上没有

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7176252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:16:02  来源:igfitidea点击:

Oracle ORA-12154 error on local IIS, but not with Visual Studio Development Server

asp.netoracleiistns

提问by Fabio

I've got an ASP.NET application that can connect to Oracle when it's started by Visual Studio Development Server, but when I deploy it to my local IIS, it does not connect, showing the "ORA-12154: TNS:could not resolve the connect identifier specified" error.

我有一个 ASP.NET 应用程序,当它由 Visual Studio Development Server 启动时可以连接到 Oracle,但是当我将它部署到本地 IIS 时,它无法连接,显示“ORA-12154:TNS:无法解析指定的连接标识符”错误。

My connection string was:

我的连接字符串是:

Data Source=ABC; User Id=USER; Password=PASSWORD;

Tt's using TNS. My tnsnames.ora is located at C:\oracle\instantclient_10_2\network\admin, and my ORACLE_HOME system variable is pointing to C:\oracle\instantclient_10_2.

Tt 正在使用 TNS。我的 tnsnames.ora 位于 C:\oracle\instantclient_10_2\network\admin,我的 ORACLE_HOME 系统变量指向 C:\oracle\instantclient_10_2。

To make it work, I changed the connection string to:

为了使它工作,我将连接字符串更改为:

"SERVER=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = server1.theplaceiwork.com)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = server2.theplaceiwork.com)(PORT = 1521))(LOAD_BALANCE = yes))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ABC)(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC))));uid=USER;pwd=PASSWORD;"

So TNS is used no longer.

所以不再使用TNS。

But I'd like to know why I can connect using TNS while debbuging with Visual Studio, but when using IIS I can't.

但是我想知道为什么我可以在使用 Visual Studio 进行调试时使用 TNS 进行连接,但是在使用 IIS 时却不能。

Any tips?

有小费吗?

PS. I can use SqlDeveloper with TNS showing no connection errors.

附注。我可以使用 SqlDeveloper 和 TNS 显示没有连接错误。

Thanks

谢谢

回答by rick schott

Make sure Network Service has access to your TNS directories or change your App Pool to run as you.

确保网络服务可以访问您的 TNS 目录或更改您的应用程序池以按照您的方式运行。

回答by Jaanus

Found answer here:

在这里找到答案:

Granting access to IIS 7.5 ApplicationPoolIdentity

授予对 IIS 7.5 ApplicationPoolIdentity 的访问权限

When using "ApplicationPoolIdentity" with IIS 7.5 the corresponding user is (a virtual system user):

IIS AppPool\<AppPoolName>

You can grant this user permissions and check security setting by searching for this user. See the full explanation here:

http://www.iis.net/learn/manage/configuring-security/application-pool-identities

在 IIS 7.5 中使用“ApplicationPoolIdentity”时,对应的用户是(虚拟系统用户):

IIS AppPool\<AppPoolName>

您可以通过搜索此用户来授予此用户权限并检查安全设置。请参阅此处的完整说明:

http://www.iis.net/learn/manage/configuring-security/application-pool-identities

So basically just give permission to Oracle folder to the App Pool virtual user.

所以基本上只是将 Oracle 文件夹的权限授予 App Pool 虚拟用户。

回答by Shiraz Bhaiji

The difference is:

区别在于:

  • When you are debugging in Visual Studio you are in the security of the logged in user (you)
  • When you are running in IIS you are in the security context of the identity of the application pool. Default is Network Service.
  • 在 Visual Studio 中进行调试时,您处于登录用户(您)的安全中
  • 当您在 IIS 中运行时,您处于应用程序池标识的安全上下文中。默认为网络服务。

回答by John

I'd configured my app pool to run in the context of ApplicationPoolIdentity as @Jaanus describes.

正如@Jaanus 所描述的,我已将我的应用程序池配置为在 ApplicationPoolIdentity 的上下文中运行。

The virtual account "IIS AppPool\MyAppPoolName" had been granted read and execute permission on the Oracle folder, however, permissions weren't being inherited from this folder. I had to traverse the Oracle folder structure to see where permissions inheritance was stopping and explicitly enable it from that point.

虚拟帐户“IIS AppPool\MyAppPoolName”已被授予对 Oracle 文件夹的读取和执行权限,但是,权限并未从该文件夹继承。我必须遍历 Oracle 文件夹结构以查看权限继承在哪里停止并从那时起显式启用它。

I found the problem using Process Monitorfrom SysInternals / Microsoft:

我使用SysInternals / Microsoft 的Process Monitor发现了问题:

  1. Start capturing
  2. Run the code that accesses the Oracle resources and wait for the exception to be raised by Visual Studio.
  3. Stop capturing.
  4. Filter the Result field for the string "ACCESS DENIED".
  1. 开始捕捉
  2. 运行访问 Oracle 资源的代码并等待 Visual Studio 引发异常。
  3. 停止捕捉。
  4. 过滤字符串“ACCESS DENIED”的结果字段。

回答by Hernaldo Gonzalez

In my case, I use Windows 7, IIS 7, Visual Studio 2010. For some reason I have installed 2 Oracle clients, 10.2 and 11.2 (I have 2 TNSNAMES.ORA in two differents path). When I use F5, Visual Studio use one TNSNAME and when I use IIS, It use the other TNSNAME!

就我而言,我使用 Windows 7、IIS 7、Visual Studio 2010。出于某种原因,我安装了2 个 Oracle 客户端,10.2 和 11.2(我在两个不同的路径中有 2 个 TNSNAMES.ORA)。当我使用 F5 时,Visual Studio 使用一个 TNSNAME,当我使用 IIS 时,它使用另一个 TNSNAME!

If I use CMD and write:

如果我使用 CMD 并写:

tnsping ORCL

It give me the Oracle vertion I use is: 10.2 and not 11.2. I try turn off the Windows Firewall and not work. I try login in IIS->AppPool with my Windows Account and either not work.

它给了我我使用的 Oracle 版本:10.2 而不是 11.2。我尝试关闭 Windows 防火墙,但不起作用。我尝试使用我的 Windows 帐户登录 IIS->AppPool,但还是无法正常工作。

Finally to fix (after 2 days reading a lot of solutions in stackoverflow and others):

最后修复(2天后在stackoverflow和其他人中阅读了很多解决方案):

  • I give read access to both path C:\oracle\productand C:\app\user\productto Everyone account user, because I not found Network Serviceaccount.

  • In IIS -> AppPool, I set ApplicationPoolIdentityto my Pool.

  • In IIS I recycle the AppPool and Restart my WebSite.

  • 我将路径C:\oracle\productC:\app\user\product 的读取访问权限授予Everyone 帐户用户,因为我没有找到网络服务帐户。

  • 在 IIS -> AppPool 中,我将ApplicationPoolIdentity设置为我的 Pool。

  • 在 IIS 中,我回收 AppPool 并重新启动我的网站。

and It Works!

它有效!

回答by imbrion

Posting my case because it took entirely too long to figure out.

发布我的案例是因为花了很长时间才弄清楚。

I didn't have access to adjusting the folder permissions and setting the Application Pool Identity did nothing.

我无权调整文件夹权限,并且设置应用程序池标识没有任何作用。

Ended up having to edit the Anonymous Authentication credentials of the individual site to my own and the application pool to Network Service. Hopefully this will help someone in a similarly frustrating situation one day.

最终不得不将单个站点的匿名身份验证凭据编辑为我自己的,并将应用程序池编辑为网络服务。希望有一天这能帮助处于同样令人沮丧的境地的人。

回答by Refael

If you are using ApplicationPoolIdentity, Make sure ApplicationPoolIdentity has access to your TNS directories.

如果您使用的是 ApplicationPoolIdentity,请确保 ApplicationPoolIdentity 可以访问您的 TNS 目录。

See here how to authorize: IIS7 Permissions Overview - ApplicationPoolIdentity

在这里查看如何授权: IIS7 权限概述 - ApplicationPoolIdentity

回答by jessewolfe

I had this issue and tried everything above with no luck. So posting one more thing that was overlooked that could be at cause. Your sqlnet.ora file (same directory as the tnsnames.ora) must exist and have TNS properly configured:

我遇到了这个问题,并尝试了以上所有方法,但都没有运气。所以再发布一件被忽视的事情,这可能是有原因的。您的 sqlnet.ora 文件(与 tnsnames.ora 相同的目录)必须存在并正确配置了 TNS:

#SQLNET.AUTHENTICATION_SERVICES = (NTS)
NAMES.DIRECTORY_PATH = (EZCONNECT,TNSNAMES)

EZCONNECT is optional but it's very useful in some situations, so I included it.

EZCONNECT 是可选的,但它在某些情况下非常有用,因此我将其包含在内。

It was this last thing that enabled my app to work. Hope this helps.

这是使我的应用程序能够工作的最后一件事。希望这可以帮助。