简体   繁体   English

ASP.NET/C#连接到Oracle DB

[英]ASP.NET/C# connect to Oracle DB

I need to access a view on an oracle server with an ASP.NET website. 我需要使用ASP.NET网站访问Oracle服务器上的视图。 It works if I debug the website through visual studio(press F5 in VS2012), but when I go to the version hosted on my local IIS (LocalHost/) I get this error: 如果我通过Visual Studio调试网站(在VS2012中按F5),则可以正常工作,但是当我转到本地IIS(LocalHost /)上托管的版本时,出现此错误:

Oracle.DataAccess.Client.OracleException: ORA-12154: TNS:could not resolve the connect identifier specified

A lot of the information I'm finding is related to the deprecated System.Data.OracleClient and I'm using Oracle.DataAccess.dll File version 4.112.3.0, Assembly version 2.112.3.0. 我发现的许多信息都与不推荐使用的System.Data.OracleClient有关,并且我正在使用Oracle.DataAccess.dll文件版本4.112.3.0,程序集版本2.112.3.0。

I set the AppPool it's running in to Enable 32-Bit Application=True based on some other people with a similar issue, I think everything else is default settings. 我基于存在类似问题的其他一些人,将正在运行的AppPool设置为Enable 32-Bit Application=True ,我认为其他所有内容都是默认设置。

I've tried using the gacutil to make sure it is installed in the gac. 我尝试使用gacutil来确保它已安装在gac中。

I also made a small winForms application that works and can access the data. 我还制作了一个小型的winForms应用程序,该应用程序可以工作并且可以访问数据。

I've tried a couple connection strings: 我尝试了几个连接字符串:

This one works: 这个作品:

"Data Source=SOURCE;Persist Security Info=True;Password=****;User Id=****;"

This one doesn't work, I can't figure out a valid SERVICE_NAME : 这不起作用,我找不到有效的SERVICE_NAME

"user id=****;password=****;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=****)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=****)));"

I always get this error: 我总是收到此错误:

Oracle.DataAccess.Client.OracleException: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Places I've looked for SERVICE_NAME 我寻找过的地方SERVICE_NAME

I checked the connection I was able to establish with the first connection string and the SERVICE_NAME was either blank or sys$users depending on the query I ran. 我检查了我可以使用第一个连接字符串建立的连接,而SERVICE_NAME是空白还是sys$users具体取决于运行的查询。

I found three files named tnsnames.ora ; 我找到了三个名为tnsnames.ora文件; one was completely blank, the SERVICE_NAME in the other two were Worker and <database service name> . 一个完全空白,其他两个中的SERVICE_NAMEWorker<database service name>

NOTE: I don't have access to the server, just credentials for this one view. 注意:我无权访问服务器,只有该视图的凭据。

I found the SERVICE_NAME with this: select sys_context('userenv','db_name') from dual; 我发现带有此名称的SERVICE_NAMEselect sys_context('userenv','db_name') from dual; and used the second connection string from the question: 并使用了问题中的第二个连接字符串:

"user id=****;password=****;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=****)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=****)));"

Thanks for all the help. 感谢您的所有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM