我嘗試從正在開發的C#2008速成版應用程序連接到遠程Oracle 10g數據庫時遇到錯誤。我試圖在開發中使用極簡主義的非侵入式方法,以便將ClickOnce部署到用戶工作站。嘗試從採用最小設置配置的C#程序連接到Oracle 10g數據庫時出錯
就上述調查過下列文件(除其他..) -
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'。
(在 '趕上(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 catch。
對不起,但希望這是有道理的? 任何幫助/建議表示讚賞!
你能ping'myServer'?你嘗試通過sqlplus連接嗎? – V4Vendetta 2011-12-22 12:34:58
你可以t''myOracleDb'嗎? – Shai 2011-12-22 12:45:20
'NullReferenceException'不是問題的原因。它發生在您檢查VisualStudio中的異常時。這是一個調試工件,可以忽略。不幸的是,真正的異常似乎不包含任何錯誤信息。或者你在某處忽略了它? – Codo 2011-12-22 12:48:44