1,105,581 Community Members

Login Page Database connection to MSAccess

Member Avatar
bravo659
Light Poster
27 posts since May 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
Paladine
Master Poster
812 posts since Feb 2003
Reputation Points: 138 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 5 [?]
Team Colleague
 
0
 

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

Member Avatar
bravo659
Light Poster
27 posts since May 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

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.

Member Avatar
Paladine
Master Poster
812 posts since Feb 2003
Reputation Points: 138 [?]
Q&As Helped to Solve: 28 [?]
Skill Endorsements: 5 [?]
Team Colleague
 
0
 

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!

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.

Member Avatar
arjunsasidharan
Practically a Posting Shark
812 posts since Aug 2006
Reputation Points: 297 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 0 [?]
 
0
 

well i tried n it didn work.. wher shud i write tht code line??

Member Avatar
decklon
Newbie Poster
4 posts since May 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

This codes works. I also need to fetch the user's full name and the account type into a variable, in order to be able to welcome the user by his full name. How do i do that? Thanx

Member Avatar
decklon
Newbie Poster
4 posts since May 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

how do i change background image on a command button at a runtime? Thanx

Member Avatar
arjunsasidharan
Practically a Posting Shark
812 posts since Aug 2006
Reputation Points: 297 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 0 [?]
 
0
 

i guess you can do that in the form_load event.

Call the button in the load event

button1.image = (the path where you have the image of the button or place it in the bin)

Member Avatar
decklon
Newbie Poster
4 posts since May 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have a form (frmLogin) on which i have 4 command button n 1 is btnLogIn. so need to change the image on the btnLogIn after the user has logged In.

i had wanted to use something like imageList. Plz help
Thanx

Member Avatar
vineet sikarvar
Newbie Poster
1 post since Aug 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

[i have problem with that code could u plz send me the correct code to my e-mail id that is <snipped email> i will be very thankfull of you

Member Avatar
arjunsasidharan
Practically a Posting Shark
812 posts since Aug 2006
Reputation Points: 297 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 0 [?]
 
0
 

place the

conn.Open() under the Try - Catch.. it will work

Member Avatar
echocpt
Newbie Poster
8 posts since Aug 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ok, well i no longer have the problem you guys have had. I don;t no what is wronge so ill ask you. ok the line

Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader

it apperes with the error "Syntax error in FROM clause"

Anyhelp were im going wronge?

Thanks

Member Avatar
Reshad Azizi
Newbie Poster
1 post since Jun 2010
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Hello every one,

i have a database in SQL Server 2008 with some login--> User
how to connect to the database via registered Login or User from a VN.net application
how to creat a login form for it to access sql server registered logins--> user

thank you in advance

Member Avatar
javedsalat
Newbie Poster
1 post since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

open connection befor declaring the ExecuteReader
like this
Dim sql = "SELECT Username,password FROM Login WHERE Username = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand(sql, con)

Dim dr As OleDbDataReader = cmd.ExecuteReader

Member Avatar
renzlo
Junior Poster
143 posts since Oct 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Heading Here

Sub-Heading Here

  1. Item One
  2. Item Two
  3. Item Three
  • Item One
  • Item Two
  • Item Three

    Code blocks are created by indenting at least 4 spaces
    ... and can span multiple lines

    Inline Code Example Here Link Anchor Text

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article