| | |
Login Page Database connection to MSAccess
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2005
Posts: 13
Reputation:
Solved Threads: 0
I been working on this login page for months, and to no avail can have the program working. I am using the MSAccess Database and using VB.Net. This is a windows application creating a login page. The following is the code that I been working on:
Dim mypath = Application.StartupPath & "\password.mdb"
Dim Password = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Documents and Settings\Owner\My Documents\OLEDB\password.mdb")
Dim cmd As OleDbCommand
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim sql = "SELECT Username,Password FROM Password WHERE Username = '" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"
cmd = New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Try
conn.Open()
Catch ex As InvalidOperationException
MsgBox(ex.Message)
End Try
Try
If dr.Read = False Then
MessageBox.Show("Authentication Failed...")
Else
MessageBox.Show("Login Successful...")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If conn.State <> ConnectionState.Closed Then
conn.Close()
End If
Dim form As New Form2
form.Show()
End Sub
The above code generates an error that points to the cmd.ExecuteReader
It says that the error : "ExecuteReader requires an open connection and available connection. The connection's current state is closed."
How can I use the open state for the ExecuteReader?
Dim mypath = Application.StartupPath & "\password.mdb"
Dim Password = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Documents and Settings\Owner\My Documents\OLEDB\password.mdb")
Dim cmd As OleDbCommand
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim sql = "SELECT Username,Password FROM Password WHERE Username = '" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"
cmd = New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Try
conn.Open()
Catch ex As InvalidOperationException
MsgBox(ex.Message)
End Try
Try
If dr.Read = False Then
MessageBox.Show("Authentication Failed...")
Else
MessageBox.Show("Login Successful...")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If conn.State <> ConnectionState.Closed Then
conn.Close()
End If
Dim form As New Form2
form.Show()
End Sub
The above code generates an error that points to the cmd.ExecuteReader
It says that the error : "ExecuteReader requires an open connection and available connection. The connection's current state is closed."
How can I use the open state for the ExecuteReader?
OK well the error is telling you exactly what is wrong. ExecuteReader requires an open connection and available connection
You need to add this line of code before you ExecuteReader. conn.Open()
Hope this helps
You need to add this line of code before you ExecuteReader. conn.Open()
Hope this helps
•
•
Join Date: May 2005
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Paladine
OK well the error is telling you exactly what is wrong. ExecuteReader requires an open connection and available connection
You need to add this line of code before you ExecuteReader. conn.Open()
Hope this helps
Find it difficult, but will continue on it.
Glad it worked
If you have troubles with Store Procedures or anything in SQL/Access just post on the forums, someone will be glad to help!
If you have troubles with Store Procedures or anything in SQL/Access just post on the forums, someone will be glad to help!
•
•
•
•
Originally Posted by bravo659
I really did because I tried it, and was missing in my coding. It is fixed and running good. I just need to be caredful how i code. The error message really drove me crazy, and thanks to you developers that assisted me in correcting my code. I will practice more. Now I am trying to learn the Stored Procedures.
Find it difficult, but will continue on it.
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Creating Time Delays in my code
- Next Thread: What happened to VB?
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add arithmetic array assignment basic binary box button buttons center click code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 plugin port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog serial server sorting sql sqldatbase storedprocedure string temp textbox timer updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





