简体   繁体   English

VS 2010 C#Express上的Oracle数据库连接失败

[英]Oracle Database connection failure on VS 2010 C# express

I am new to VS and database. 我是VS和数据库的新手。 The project I was working on is trying to moderize an old software from VB6 to VS 2010 C#. 我正在从事的项目试图将旧版软件从VB6简化为VS 2010 C#。 This requires to search an external database. 这需要搜索外部数据库。 So I am trying to connect to that database by using OracleConnection(). 因此,我尝试使用OracleConnection()连接到该数据库。 I am using Visual Studio 2010 Express on Windows 7 Enterprise. 我在Windows 7企业版上使用Visual Studio 2010 Express。 I downloaded the Oracle Data Access Components (ODAC 11.2 Release 5 which is the newest, 32bit). 我下载了Oracle数据访问组件(ODAC 11.2第5版,最新的32位)。 The TNSNAMES.ora file and connection string were both correctly settled. TNSNAMES.ora文件和连接字符串均已正确设置。

Right now I can use Sql*Plus to connect to the database. 现在,我可以使用Sql * Plus连接到数据库。 Also the old VB6 version software works well in retrieving information from the database(it won't do the work if I did not have ODAC and set up the tnsnames.ora correctly). 同样,旧的VB6版本软件也可以很好地从数据库中检索信息(如果我没有ODAC并正确设置了tnsnames.ora,它将无法正常工作)。 But, my VS C# does not. 但是,我的VS C#没有。 It cannot open the connection. 它无法打开连接。 The error message is "ORA-12545: Connect failed because target host or object does not exist". 错误消息是“ ORA-12545:连接失败,因为目标主机或对象不存在”。 And if I changed the DB host address to IP address, it would give me " ORA-12560: TNS:protocol adapter error". 而且,如果我将数据库主机地址更改为IP地址,则会显示“ ORA-12560:TNS:协议适配器错误”。

I assume there is a problem with the VS 2010 Express IDE. 我认为VS 2010 Express IDE有问题。 Does anyone has any idea on that? 有人对此有任何想法吗? I tried to reinstall the ODAC and it does not help. 我试图重新安装ODAC,但没有帮助。 Thanks so much in advance. 非常感谢。

My code is exactly the same as here connect to oracle XE using c# 2010 express 我的代码与此处使用c#2010 express连接到oracle XE的代码完全相同

Update--Solved 更新-已解决

I finally figured out this question. 我终于找到了这个问题。 In my case, this is somehow related with the DLL in Global Assembly Cache. 就我而言,这与全局程序集缓存中的DLL有某种联系。 I found my project is compiling against an odd ODAC designed for .NET 2.0. 我发现我的项目正在针对.NET 2.0设计的奇怪ODAC进行编译。 I tried to redirect the reference of OracleDBAccess but did not help. 我试图重定向对OracleDBAccess的引用,但没有帮助。 Then I started a new project, set up the reference right and then copied all the code there. 然后,我开始一个新项目,设置引用权限,然后将所有代码复制到那里。 It worked out in the end. 最终解决了。

The difference is SqlPlus uses a different data provider to connect than .Net. 区别在于SqlPlus使用与.Net不同的数据提供程序进行连接。 I have a blog post that talks about the minimum requirements needed for .net and oracle to work together. 我有一篇博客文章,讨论了.net和oracle协同工作所需的最低要求。 The main points to consider is to make sure you have the correct data provider (32 / 64 bit) and your oracle bin folder is in the path statement for the OS. 要考虑的重点是确保您具有正确的数据提供程序(32/64位),并且oracle bin文件夹位于操作系统的路径语句中。

The difference is SqlPlus uses a different data provider to connect than .Net. 区别在于SqlPlus使用与.Net不同的数据提供程序进行连接。 I have a blog post that talks about the basic requirements. 我有一篇博客文章讨论了基本要求。

Blog Post Link 博客文章链接

-Text from Post -帖子中的文字

Download the latest Oracle 11g2 client software from Oracle. 从Oracle下载最新的Oracle 11g2客户端软件。

Note – Be sure to determine which bit level you need if using a 64 bit operating system. 注–如果使用64位操作系统,请确保确定所需的位级别。 If your apps are compiled to 32 bit specifically then you must use the 32 bit oracle client. 如果您的应用程序专门编译为32位,则必须使用32位oracle客户端。 If they are compiled to run natively – then you must use the 64 bit oracle client software. 如果将它们编译为本地运行,则必须使用64位oracle客户端软件。

  1. Extract the zip file to a directory 将zip文件解压缩到目录中

  2. Open the folder and launch the setup.exe file as an administrator 打开文件夹并以管理员身份启动setup.exe文件

  3. Select the custom option in Step 1 of 8 for what type of Installation you want and click next 在第8步的第1步中选择所需的安装类型的自定义选项,然后单击下一步

  4. Now choose the Oracle Data Provider for .NET option and click next 现在选择Oracle Data Provider for .NET选项,然后单击下一步。

  5. Complete the remaining steps using the default options 使用默认选项完成其余步骤

  6. Once complete – navigate to the following folder 完成后–导航至以下文件夹

    [installation path]\\product\\11.2.0\\client_1\\network [安装路径] \\ product \\ 11.2.0 \\ client_1 \\ network

  7. Create a new folder named admin 创建一个名为admin的新文件夹

  8. Copy an existing sqlnet.ora and tnsnames.ora file into the admin directory 将现有的sqlnet.ora和tnsnames.ora文件复制到admin目录中

  9. Test the installation with a .net application or you can use one the OracleConnectionTesting utilities provided on this blog here 使用.net应用程序测试安装,或者您可以使用此博客上提供的OracleConnectionTesting实用程序中的一种。

.Net Testing Utility for Oracle 适用于Oracle的.Net测试实用程序

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

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