【发布时间】:2012-01-26 02:16:51
【问题描述】:
我在尝试从我正在开发的 C# 2008 Express Edition 应用程序连接到远程 Oracle 10g 数据库时遇到错误。我正在尝试使用一种极简、非侵入式的开发方法,以便将 ClickOnce 部署到用户工作站。
关于上述内容,我调查了以下文件(以及其他文件..)-
What is the minimal setup required to deploy a .NET application with Oracle client 11?
http://jeremybranham.wordpress.com/2011/04/25/oracle-instant-client-with-odp-net/
http://ora-00001.blogspot.com/2010/01/odpnet-minimal-non-intrusive-install.html
http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c
Connect to Oracle with odp.net and the OCI from C#
鉴于我遇到的错误,我创建了一个简单的测试应用。由带有一个按钮的单个 (wpf) 页面组成。 在按钮的单击事件中,我尝试创建到 Oracle 数据库的连接 -
private void button1_Click( object sender, RoutedEventArgs e )
{
OracleConnection oraConnect;
// string previously used OK in other projects
string connectionString = "Data Source=" +
"(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = myServer)(PORT = 1521)))" +
"(CONNECT_DATA =(SERVICE_NAME = myOracleDb)))" +
";Password=myPw;User ID=myID;";
using ( oraConnect = new OracleConnection( connectionString ) )
{
try
{
if ( oraConnect.State == ConnectionState.Closed )
{
oraConnect.Open();
MessageBox.Show( "oraConnect is attempting to open.." );
}
else
MessageBox.Show( "oraConnect open to DB: " + oraConnect.ServerVersion.ToString() );
}
catch ( NullReferenceException nullExcept )
{
MessageBox.Show( "Caught error: ." + nullExcept.ToString() );
}
catch ( OracleException dbEx )
{
MessageBox.Show( "OraException - " + dbEx.Message.ToString());
}
catch ( Exception ex )
{
Exception current;
current = ex;
while ( current != null )
{
current = current.InnerException;
}
MessageBox.Show( "Db base exception - " + ex.GetBaseException().ToString() );
}
finally
{
oraConnect.Close();
}
}
}
根据上述文章中的信息,我确保以下 Dll 位于我的“bin”文件夹中 -
• oci.dll
• ociw32.dll
• orannzsbb10.dll
• oraocci10.dll
• oraociicus.dll
• msvcr71.dll
(最后一个绝望地命名...)并引用了“Oracle.DataAccess.dll”。
错误消息(在“catch (OracleException dbEx)”处)是 -
"Oracle.DataAccess.Client.OracleException was caught
Message=""
StackTrace:
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 OracleConnectionTest.Window1.button1_Click(Object sender, RoutedEventArgs e) in C:\Documents\Visual Studio 2008\Projects\OracleConnectionTest\OracleConnectionTest\Window1.xaml.cs:line 69
InnerException: "
Line 69 is 'oraConnect.Open();'.
另外,报告如下——
"((Oracle.DataAccess.Client.OracleException)($exception)).DataSource' threw an exception of type 'System.NullReferenceException".
我从数据源中的 NullReferenceException 假设问题出在其中一个 dll 上(?),因为我在尝试引用之前“新建”了上面的 OracleConnection。
另外,代码执行跳转'catch(NullReferenceException nullExcept)' 并直接进入 OracleException 捕获。
抱歉,我说得有点意思,但希望这是有道理的吗? 任何帮助/建议表示赞赏!
【问题讨论】:
-
你能ping通
myServer吗?你试过通过 sqlplus 连接吗? -
你能 tnsping 'myOracleDb' 吗?
-
NullReferenceException不是问题的原因。当您在 VisualStudio 中检查异常时会发生这种情况。这是一个调试工件,可以忽略。不幸的是,真正的异常似乎不包含任何错误消息。还是您在某个地方忽略了它?
标签: c# oracle clickonce oracleexception