Gridview人口

时间:2012-05-07 14:15:26

标签: c# asp.net

我整个周末都在看这段代码。我知道有数据,我可以通过其他查询,但GridView不会显示和填充。建议?

        string sqlSelection =
                    "SELECT * FROM [COMPANY].[dbo].[parking] ";

        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DATACONNECTION"].ToString());
        //This connection works in MSSMS and in other pages I have on the same server

        SqlDataAdapter sda = new SqlDataAdapter(sqlSelection, cn);

        SqlCommandBuilder scb = new SqlCommandBuilder(sda);

        DataTable dTable = new DataTable();

        sda.Fill(dTable);
            //debug shows: dTable <not set>


        GrdDynamic.Visible = true;
        GrdDynamic.DataSource = dTable;
        GrdDynamic.DataBind();

1 个答案:

答案 0 :(得分:0)

当连接字符串中的帐户没有数据库权限时,我遇到了这种情况,因为Web服务无法访问该帐户。如果您使用的是计算机帐户(不是sql登录),请尝试创建sql登录(如果可能)并将其分配给db。或者您可以暂时使用匿名帐户来使用您用于管理工作室的登录(更可能是您自己)。当Web服务器由于路由问题而无法看到SQL服务器时,我也遇到了这种情况。您可以通过转到服务器并尝试ping sql server来测试最后一个。最糟糕的情况是防火墙阻止端口连接。我不确定对这种情况进行可靠的防火测试,因为它很大程度上取决于您的网络配置方式。

相关问题