C# Oracle 数据库 10g 问题

发布于 2024-09-05 21:32:17 字数 1163 浏览 9 评论 0原文

好吧,问题如下:

我有一个使用 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;
        }
    }

Well, the problem is as follows:

I have a WPF Application built using the C#, I have known how to connect to oracle database engine, yet I need some help in it.

first, I want to know how to add the server to the connection string ...

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

is it the provider or the data source? and the server is on my pc should I write it localhost or 127.0.0.1 then the port? and how do I add the port is it server:port or should I add another parameter?

second, I have created a function that executes a query sent to it as a parameter, I want to put the query result in a DataSet yet I don`t know how to convert the result to a DataSet.

This is my function:

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;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2024-09-12 21:32:17

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

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

For an example of Oracle Connection strings Take a look at this URL as it will contain all of the info needed.
connectionstrings.com/oracle. On another note unless you really need to don't bother with the ODP.Net provider as it is a pain to install and you will run into x64 issue with Oracle 10g. I find I have fewer problems using System.Data.OracleClient which is going to be deprecated in .Net 4.0 unfortunately.

As for specifying the Port typically all of that information is specified in your TNS file and you just specify which TNS listing to use in your connection string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文