oracle OracleConnection 抛出空异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12460384/
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
OracleConnection is throwing empty exception
提问by Laggel
I'm trying to connect to my Oracle Database from my new PC. I've just installed Visual Studio and the ODAC. But when I try to do a simple connect Im getting an exception with an empty message, empty source, empty number, just with the error code which is -2147467259.
我正在尝试从我的新 PC 连接到我的 Oracle 数据库。我刚刚安装了 Visual Studio 和 ODAC。但是当我尝试做一个简单的连接时,我收到一个空消息、空源、空编号的异常,只是错误代码是-2147467259。
OracleConnection Prueba;
Prueba = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=XXX.XXX.XXX.XXX)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXXX)));User Id=XXX;Password=XXX;Pooling=true;Max Pool Size=10;Min Pool Size=1");
Prueba.Open();
Exception Details
This is the Exception.ToString() code:
异常详细信息
这是 Exception.ToString() 代码:
"Oracle.DataAccess.Client.OracleException at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
at Oracle.DataAccess.Client.OracleConnection.Open()
at OracleConnectionS.Program.Main(String[] args) in C:\Users\Simetri\Documents\Visual Studio 2010\Projects\OracleConnection\OracleConnection\Program.cs:line 19"
"Oracle.DataAccess.Client.OracleException at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32) errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
at Oracle.DataAccess.Client.OracleConnection.Open()
at OracleConnectionS.Program.Main(String[] args) in C:\Users\Simetri\Documents\Visual Studio 2010\Projects \OracleConnection\OracleConnection\Program.cs:line 19"
Any idea about why could this be happening?
知道为什么会发生这种情况吗?
UPDATE
更新
If I run visual studio as Administrator I dont get the exception and I can connect to the database just fine.
如果我以管理员身份运行 Visual Studio,则不会出现异常,并且可以正常连接到数据库。
I tried giving FULL CONTROL permission to the Oracle Directory C:\Oracle
. But if I run Visual Studio in a normal way (not as administrator) I keep getting the exception.
我尝试给予 Oracle Directory FULL CONTROL 权限C:\Oracle
。但是如果我以正常方式(不是以管理员身份)运行 Visual Studio,我就会不断收到异常。
Background Info
- I'm using Windows 7 64 bit
- Visual Studio 2010
- I can connect just find with SQL*PLUS
背景信息
- 我使用的是 Windows 7 64 位
- Visual Studio 2010
- 我可以通过 SQL*PLUS 连接 find
回答by Laggel
So after installing all sort of versions of ODAC and searching to every single post related to this.
因此,在安装各种版本的 ODAC 并搜索与此相关的每个帖子之后。
At the end Clean Install of the 32bit version was the solution.
最后,32 位版本的 Clean Install 是解决方案。
- First you need to unistall all your other oracle client you have ever installed.
- After that, look for any ODAC version you want (latest if posible) but be sure to download the 32 bit version.
- 首先,您需要卸载您曾经安装过的所有其他 oracle 客户端。
- 之后,查找您想要的任何 ODAC 版本(如果可能是最新的),但一定要下载 32 位版本。
WHY?
为什么?
Well is something related to the version in which Visual Studio is developed in. If you are developing a console application you will have not problem with the client version, but if you are using a web project then you definitely need the 32 bit version.
嗯,这与开发 Visual Studio 的版本有关。如果您正在开发控制台应用程序,那么客户端版本不会有问题,但如果您使用的是 Web 项目,那么您肯定需要 32 位版本。
- Finally be sure that all of your projects in visual studio the target platform is "32 bit"
- and reference the new Oracle.DataAccess.dll that you have just installed
- 最后确保您在 Visual Studio 中的所有项目的目标平台都是“32 位”
- 并引用您刚刚安装的新 Oracle.DataAccess.dll
回答by Andrew Walters
Please try re-formatting your connection string into this form and see how it works
请尝试将您的连接字符串重新格式化为这种形式,看看它是如何工作的
<add name="LoisDataAccess" connectionString="Data Source=LOISPRD;Persist Security Info=True;User ID=ABC;Password=DEF" providerName="System.Data.OracleClient" />
回答by Yahia
If the client you are using is an "Instant Client" then you might be better off by copying some Oracle-DLLs into your solution - for a walktrhough see this.
如果您使用的客户端是“即时客户端”,那么将一些 Oracle-DLL 复制到您的解决方案中可能会更好 - 有关演练,请参阅此。
IF possible I would recommend to use a different .NET provider... in my experience most commercial ones are much less problematic than the Oracle .NET provider - see here on SO.
如果可能,我会建议使用不同的 .NET 提供程序......根据我的经验,大多数商业提供程序的问题比 Oracle .NET 提供程序少得多 - 请参阅此处的 SO。