Thursday, March 8, 2012

Connection to SQL

I am gettin the following error,,

Exception Details: System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. Invalid connection string attribute

This is the string can anyone help?

Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet

DBConn = New OleDbConnection("Provider=sqloledb;" _
& "server=localhost;" _
& "InitialCatalog=BOOKSTORE;" _
& "User Id=sa;" _
& "Password=Pswd:")

DBCommand = New OleDbDataAdapter _
("Select StudentID from " _
& "Students Where " _
& "StudentName = '" & txtStudentName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", DBConn)
DBCommand.Fill(DSLogin, _
"StudentInfo")
If DSLogin.Tables("StudentInfo"). _
Rows.Count = 0 Then
lblMessage.Text = "The student name and password " _
& "were not found. Please try again."
Else
Session("StudentID") = DSLogin.Tables("StudentInfo"). _
Rows(0).Item("StudentID")
Session("StudentName") = txtStudentName.Text
Response.Redirect("./home_room.aspx")
End IfAre you using Mixed mode or windows authentication for sql Server?

Also, I thoght you needed to open the connection first, not totally sure.

No comments:

Post a Comment