在Visual Studio中未打开连接

问题描述:

对于我的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

你应该尝试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; 
} 

你在运行代码时是否打开了oracle管理?

解决此错误信息,最好的办法是使用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:语句被忽略“}