Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Sub FetchSQLData()
Dim cnn As SqlConnection
cnn = New SqlConnection("Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI")
cnn.Open()
Dim cmd As SqlCommand
cmd = New SqlCommand("select * from employees")
cmd.Connection = cnn
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
Response.Write("<table border=1><tr><td>姓名</td><td>职务</td></tr>")
Do While dr.Read()
Response.Write("<tr><td>" + dr.GetString(1) + "" + dr.GetString(2) + "</td>")
Response.Write("<td>" + dr.GetString(3) + "</td></tr>")
Loop
Response.Write("</table>")
dr.Close()
cnn.Close()
dr = Nothing
cmd = Nothing
cnn = Nothing
End Sub
End Class
在和数据库连接时老报错
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'HUST-LIU\ASPNET'.Source Error:
Line 27: cnn = New SqlConnection("Initial Catalog=Northwind;Data Source=HUST-LIU;Integrated Security=SSPI")
Line 28: 'cnn = New SqlConnection("Server=localhost;Database=Northwind;user=sa")
Line 29: cnn.Open()
Line 30: Dim cmd As SqlCommand
Line 31: cmd = New SqlCommand("select * from employees")
我的数据库是系统登陆模式的
Public Class WebForm1
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Sub FetchSQLData()
Dim cnn As SqlConnection
cnn = New SqlConnection("Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI")
cnn.Open()
Dim cmd As SqlCommand
cmd = New SqlCommand("select * from employees")
cmd.Connection = cnn
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
Response.Write("<table border=1><tr><td>姓名</td><td>职务</td></tr>")
Do While dr.Read()
Response.Write("<tr><td>" + dr.GetString(1) + "" + dr.GetString(2) + "</td>")
Response.Write("<td>" + dr.GetString(3) + "</td></tr>")
Loop
Response.Write("</table>")
dr.Close()
cnn.Close()
dr = Nothing
cmd = Nothing
cnn = Nothing
End Sub
End Class
在和数据库连接时老报错
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'HUST-LIU\ASPNET'.Source Error:
Line 27: cnn = New SqlConnection("Initial Catalog=Northwind;Data Source=HUST-LIU;Integrated Security=SSPI")
Line 28: 'cnn = New SqlConnection("Server=localhost;Database=Northwind;user=sa")
Line 29: cnn.Open()
Line 30: Dim cmd As SqlCommand
Line 31: cmd = New SqlCommand("select * from employees")
我的数据库是系统登陆模式的
如果用这里的话.好像数据库里要有asp.net用户cnn = New SqlConnection("Initial Catalog=Northwind;Data Source=HUST-LIU;Integrated Security=SSPI")