关于asp.net 用VB连接sql server数据库(100分)在线等

来源:百度知道 编辑:UC知道 时间:2024/05/30 18:48:35
我用的是 VB.NET2003的版本

做一个最简单的数据库连接 只用了DataGrid 控件显示 数据库中的信息

我在Button 写入下面代码:
Dim str As String
str = "server=.;integrated security=sspi ;initial catalog=northwind"
Dim conn As New SqlConnection(str)
Dim cmd As New SqlCommand("select * from categories", conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
conn.Close()

--------
连接的数据库中已有的数据的一张表
用浏览器查看会出现以下错误,本人想知道怎样才可以运行不出错,我数据库用的是系统默认登陆的 考试要用 谢谢了
如果谁能解决并且给出删除 添加等代码,不胜感谢 肯定给高分

以下是出错信息///

用户 'B843F473D8A24DA\ASPNET' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: 用户 'B843F473D8A24DA\ASPNET' 登录失败。

源错误:

行 36: Dim conn As New SqlConnection(

Dim str As String
str = "server=.;User ID=sa;pwd="";Catalog=表名称;Data Source=数据库名称"
Dim conn As New SqlConnection(str)
conn.Open()
Dim cmd As New SqlCommand("select * from categories", conn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
conn.Close()

1、在SQL Server创建 “电脑名\ASPNET”用户。比如我创建HP-2V47VI88M4GB\ASPNET
2、在SQL Enterprise manager里打开“安全性”文件夹,右击“登录”,选择“新建登录……”。“常规”选项卡,“名称”填HP-2V47VI88M4GB\ASPNET,其他默认;“数据库访问”选项卡,指定访问的数据库,我指定的是Northwind数据库,然后给他赋权限:dbo,public就够了。

str = "server=.;uid=sa;pwd=;datebase=northwind"