2015-01-10 157 views
0

對於我的C#應用​​程序,我需要連接到oracle數據庫。我一直使用相同的連接,並與其他應用程序完美配合。添加了我一直使用的相同的參考:Oracle.DataAcces在Visual Studio中未打開連接

這是這個問題,我不知道如何解決它。

類型的異常「Oracle.DataAccess.Client.OracleException」發生Monime_V2.0.dll但在用戶代碼中沒有處理

其他信息:外部組件引發的異常。

這是我用來連接:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

// Oracle 
using Oracle.DataAccess.Types; 
using Oracle.DataAccess.Client; 

namespace Monime_V2._0 
{ 
    public class Database 
    { 
     protected OracleConnection conn; 
     public OracleConnection Conn 
     { 
     get 
     { 
      return this.conn; 
     } 
    } 

    public Database() 
    { 
     //dbconnectie 
     this.conn = new OracleConnection(); 
     string pcn = "dbi284945"; //login 
     string pw = "HGD7dh8daa"; //password 
     this.conn.ConnectionString = "User Id=" + pcn + ";Password=" + pw + ";Data Source=" + "//192.168.15.50:1521/fhictora" + ";"; 
    } 

這裏去理解錯了:

private List<Account> GetListAccounts() 
    { 
     List<Account> listA = new List<Account>(); 

     string sql = "select * from MT_ACCOUNT"; 
     OracleCommand cmd = new OracleCommand(sql, this.conn); 

     try 
     { 
      this.conn.Open(); // <-- This line of code sends me to the exception catcher 
      OracleDataReader reader = cmd.ExecuteReader(); 
+0

例外說什麼?你想讓我們*猜你的問題是什麼? – nvoigt

+0

你能否在Catch()函數內部放置一個斷點並查看異常? – Eru

+0

我發佈在我的問題的第一個quotet塊是我得到的。所以是的,我希望你們能猜到問題可能是什麼 – JustMo06

回答

-1

你應該嘗試public database()驗證碼:

public Database() 
{ 
     //dbconnectie 
     this.conn = new OracleConnection(); 
     string pcn = "dbi284945"; //login 
     string pw = "HGD7dh8daa"; //password 
     string connection = string.Format("User Id ={0};password={1};Data Source=//192.168.15.50:1521/fhictora;",pcn,pw); 
     this.conn.ConnectionString = connection; 
} 
-1

你在運行代碼時是否打開了oracle管理?

0

解決此錯誤信息,最好的辦法是使用OracleException:

try 
{ 
    cmd.CommandType = CommandType.Text; 
    dr = cmd.ExecuteReader(); 
} 
catch (OracleException ex) 
{ 
    Console.WriteLine("Record is not inserted into the database table."); 
    Console.WriteLine("Exception Message: " + ex.Message); 
    Console.WriteLine("Exception Source: " + ex.Source); 
} 

你得到的是什麼問題更具描述性診斷。例如,而不是這種無益的一般性錯誤消息:

類型的異常 'Oracle.DataAccess.Client.OracleException'

我得到這個:

{「ORA-06550 :行1,列7:\ nPLS-00306:調用'GETCLIENTBYID'時錯誤的參數數量或類型\ nORA-06550:行1,列7:\ nPL/SQL:語句被忽略「}

相關問題