【问题标题】:Oracle Connection Issue with GridviewGridview 的 Oracle 连接问题
【发布时间】:2012-09-26 06:56:37
【问题描述】:

我尝试在 asp.net 中连接一个 oracle 数据库。我想处理与 SqlDataSource 的连接。当我使用下面的代码时,我收到以下错误:

说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.ComponentModel.Win32Exception:系统 找不到指定的文件。

来源错误:

[Win32Exception (0x80004005): 系统找不到文件 指定。]

[SqlException (0x80131904): 网络相关或实例特定 建立与 SQL Server 的连接时出错。这 服务器未找到或无法访问。验证实例 名称正确且 SQL Server 配置为允许远程 连接。 (提供者:命名管道提供者,错误:40 - 无法 打开与 SQL Server 的连接)]

这是aspx文件:


<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org  /TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <asp:SqlDataSource
        id="SqlDataSource1"
        runat="server"
        DataSourceMode="DataReader"            
        SelectCommand="SELECT * FROM PERSON "
        ConnectionString="<%$ ConnectionStrings:OracleConnectionString %>">
    </asp:SqlDataSource>


    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" BackColor="WindowFrame" AllowSorting="true" AllowPaging="true">

        <Columns>
            <asp:BoundField HeaderText="Numarası" DataField="ID" />
            <asp:BoundField HeaderText="Adı" DataField="NAME" />
            <asp:BoundField HeaderText="Soyadı" DataField="SURNAME" />

        </Columns>

    </asp:GridView>

    <br />

</div>       
</form>


但是我可以直接连接数据库,也可以连接另一个代码文件,步骤如下:

    private void ReadOracleTypesExample(string connectionString)
    {
        OracleConnection connection = new OracleConnection(connectionString);
        connection.Open();
        OracleCommand command = connection.CreateCommand();
        try
        {
            command.CommandText = "SELECT * FROM PERSON";
            OracleDataReader reader = command.ExecuteReader();


        if (reader.HasRows)
        {
            while (reader.Read())
            {

                OracleString oraclesring2 = reader.GetOracleString(1);
                Label2.Text += ("<br />" + oraclesring2.ToString());

                OracleString oraclestring3 = reader.GetOracleString(2);
                Label3.Text += ("<br /> " + oraclestring3.ToString());
            }
        }
        else
        {
            Console.WriteLine("No rows found.");
        }
        reader.Close();

    }
    catch (Exception e)
    {
        Label1.Text = e.Message;
    }
    finally
    {
        connection.Close();
    }
}


c# 之外的工具可以访问 oracle 数据库。我无法想象为什么我不能连接到数据库,我会跑题。提前致谢。

【问题讨论】:

标签: asp.net oracle gridview connection


【解决方案1】:

为了使用 SqlDataSource 控件连接到 Oracle 数据库,您必须配置 SqlDataSource。

1 从工具箱的“数据”选项卡中,将 SqlDataSource 控件拖到您的页面上。

2 如果SqlDataSource Tasks 智能标记没有出现,右击控件,点击显示智能标记。

3 在 SqlDataSource 任务列表中,单击配置数据源。

4 在“配置数据源”对话框中,单击“新建连接”。

5 显示选择数据源对话框。

6 在数据源列表中,单击 Oracle 数据库,然后单击继续。

7 显示添加连接对话框。

8 在“服务器名称”框中,键入 Oracle 服务器的名称。

9 输入用户名和密码以连接数据库。

10 确保选中“是,保存此连接”复选框,根据需要更改连接字符串的名称,然后单击“下一步”将连接字符串信息保存在应用程序的 Web.config 文件中。

11 出现配置选择语句窗格。

12 单击下一步。

13 单击“测试查询”按钮以针对数据库测试您的查询,然后单击“完成”。

【讨论】:

  • 感谢您的快速回复。即使我在源代码样式中编辑了必要的修改,但似乎我的编辑还不够。Visual Studio 2012 所做的更改是:在 web.config:
  • 我很乐意帮助你 Varoluscu 这里有不同的字符串连接格式:connectionstrings.com
  • 我的第一个连接字符串是从那里得到的,但它没有像上面看到的那样工作。
  • Varoluscu 你的异常信息是什么?相同或新的例外
  • 我的异常,正如我在第一篇文章中所写,>>>>>>>>>>>>>>>>>>>>>>>>>>>> >
【解决方案2】:

[SqlException (0x80131904):建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与 SQL Server 的连接)]

您的连接字符串似乎有问题。您的页面无法连接到数据库。

我使用以下连接字符串:

add name="ConnectionString" connectionString="Data Source=localhost;Password=123456;User ID=TAHA";Unicode=True" providerName="System.Data.OracleClient" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2012-09-16
    相关资源
    最近更新 更多