943,788 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 824
  • ASP.NET RSS
Feb 12th, 2009
0

problem in the login code

Expand Post »
The following is my login code for my project..

ASP.NET Syntax (Toggle Plain Text)
  1. Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
  2. 'Dim sName As String
  3. Dim sUser As String
  4. Dim sPwd As String
  5. Dim blnValidUser As Boolean
  6. blnValidUser = True
  7. Dim strConn As String = "server=YOGESH\SQLEXPRESS;Trusted_Connection=yes;database=jobbunch.mdf"
  8.  
  9. 'Dim MySQL As String = "Select [Name], [Login], " & _
  10. '"[Password] from Employees " & _
  11. '"Where Login=@uid AND Password=@Pwd"
  12. Dim MySQL As String = "Select [uid],[pwd] from login where uid=@uid and pwd=@pwd "
  13. Dim MyConn As New SQLConnection(strConn)
  14. Dim objDR As SQLDataReader
  15. Dim Cmd As New SQLCommand(MySQL, MyConn)
  16. Cmd.Parameters.Add(New SqlParameter("@uid", uid))
  17. Cmd.Parameters.Add(New SqlParameter("@pwd", pwd))
  18. MyConn.Open()
  19. Try
  20. objDR = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
  21. While objDR.Read()
  22. sUser = objDR("uid")
  23. sPwd = objDR("pwd")
  24. 'sName = objDR("Name")
  25. End While
  26. 'Dim sText As String
  27. 'If sFirst = "" And sLast = "" Then
  28. ' blnValidUser = "False"
  29. 'Else
  30. ' blnValidUser = "True"
  31. 'Session("Name") = sUser
  32. 'End If
  33. Catch ex As Exception
  34. blnValidUser = "False"
  35. 'lblError.visible = "true"
  36. 'lblError.text = "Sorry Errors have occurred"
  37. Finally
  38. ValidateUser = blnValidUser
  39. MyConn.Close()
  40. End Try
  41. End Function

Basically this code is to fetch the userid and password from the database and perform the validation for the login form.
i performed the debugging activity and after line17 the execution jumps to line 22 i.e an exception is gettin occured..
pls suggest some solution.
Last edited by peter_budo; Feb 15th, 2009 at 11:17 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yorock is offline Offline
4 posts
since Feb 2009
Feb 15th, 2009
0

Re: problem in the login code

why dont you use asp.net forms authentication and autorization, and membership? you can do the same thing without writing code.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Feb 16th, 2009
0

Re: problem in the login code

What exception/error message you are getting?
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008
Feb 16th, 2009
0

Re: problem in the login code

@serkan
but in the project v r using sql server which contains the database for all users..
so v need to connect the .net application to sql server database and then execute the queries..
but if dis can be done in another way..pls suggest how to do it exactly..
thanx

@aneesh
i dont know wht kind of exception it is?
just bcoz the control is jumpin to catch statement i came 2 know ki an exception is gettin occured
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yorock is offline Offline
4 posts
since Feb 2009
Feb 17th, 2009
0

Re: problem in the login code

Rewrite your catch block like this and let me know what message u get on the label

ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. Catch ex As Exception
  3.  
  4. blnValidUser = "False"
  5. lblError.visible = "true"
  6. 'Displays exception message on label
  7. lblError.text = ex.Message
  8.  
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Adding a textbox dynamically
Next Thread in ASP.NET Forum Timeline: linkbutton





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC