【问题标题】:C# Oracle Database 10g issuesC# Oracle 数据库 10g 问题
【发布时间】:2011-03-05 13:14:54
【问题描述】:

嗯,问题如下:

我有一个使用 C# 构建的 WPF 应用程序,我知道如何连接到 oracle 数据库引擎,但我需要一些帮助。

首先,我想知道如何将服务器添加到连接字符串...

OleDbConnection conn = new OleDbConnection("provider=MSDAORA;data source=ORCL;user id=SCOTT;password=TIGER");

是提供者还是数据源?服务器在我的电脑上,我应该写localhost 还是127.0.0.1 然后是端口?以及如何添加端口是server:port 还是应该添加另一个参数?

其次,我创建了一个执行作为参数发送给它的查询的函数,我想将查询结果放在DataSet 中,但我不知道如何将结果转换为 DataSet。

这是我的功能:

public DataSet SelectQuery(String p_sSql)
    {
        DataSet ds = new DataSet();
        try
        {
            OleDbCommand myOleDbCommand = conn.CreateCommand();
            myOleDbCommand.CommandText = p_sSql.ToString();
            OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
            myOleDbDataReader.Read();
            //here I want to add the result to the DataSet ds ...
            myOleDbDataReader.Close();
            conn.Close();
            return ds;
        }
        catch (System.Exception ex)
        {
            MessageBox.Show("Error: " + ex.ToString());
            return null;
        }
    }

【问题讨论】:

    标签: c# wpf oracle-xe


    【解决方案1】:

    如果您不仅限于 ODBC,您应该尝试 ODP.NET

    http://www.oracle.com/technology/tech/windows/odpnet/index.html

    这里有一个简单的教程

    http://www.oracle.com/technology/pub/articles/cook-vs08.html

    【讨论】:

    • 我按照第二个链接中提到的关于连接的说明进行操作,但是我可以t figure out the correct connection string for my database, Im 使用Oracle 10g XE,我不知道提供程序和数据源应该是什么。跨度>
    【解决方案2】:

    有关 Oracle 连接字符串的示例 请查看此 URL,因为它将包含所需的所有信息。 connectionstrings.com/oracle。另一方面,除非您真的不需要使用 ODP.Net 提供程序,因为安装起来很痛苦,而且您会遇到 Oracle 10g 的 x64 问题。我发现使用 System.Data.OracleClient 时遇到的问题较少,不幸的是,它在 .Net 4.0 中将被弃用。

    至于指定端口,所有这些信息通常都在您的 TNS 文件中指定,您只需指定要在连接字符串中使用的 TNS 列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 2011-04-10
      相关资源
      最近更新 更多