<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
string ConnStr;
ConnStr="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=User";//User为表名
        SqlConnection conn =new SqlConnection(ConnStr);
SqlCommand comm =new SqlCommand();
comm.CommandText="dt_insertuser1";//有一dt_insertuser1的存储过程,实现的是插人;
comm.Connection=conn;
comm.CommandType=System.Data.CommandType.StoredProcedure;
                       conn.open();                         dgOutput.DataSource=comm.ExecuteReader();
dgOutput.DataBind();
                      conn.Close(); }
</script>

解决方案 »

  1.   

    编译没错误,但好象访问不了数据库错误如下:
    无法打开登录 'User'中请求的数据库。登录失败。用户 'ZHANGLEI\ASPNET' 登录失败。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 无法打开登录 'User'中请求的数据库。登录失败。用户 'ZHANGLEI\ASPNET' 登录失败。
      

  2.   

    在你的sqlserver的企业管理器的安全性->登陆中添加ZHANGLEI\ASPNET用户权限
      

  3.   

    1.在数据库添加用户'ZHANGLEI\ASPNET' 或
    2.在WebConfig中加入<identity impersonate="true" />