problem in the login code

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 4
Reputation: yorock is an unknown quantity at this point 
Solved Threads: 0
yorock yorock is offline Offline
Newbie Poster

problem in the login code

 
0
  #1
Feb 12th, 2009
The following is my login code for my project..

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: problem in the login code

 
0
  #2
Feb 15th, 2009
why dont you use asp.net forms authentication and autorization, and membership? you can do the same thing without writing code.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: problem in the login code

 
0
  #3
Feb 16th, 2009
What exception/error message you are getting?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 4
Reputation: yorock is an unknown quantity at this point 
Solved Threads: 0
yorock yorock is offline Offline
Newbie Poster

Re: problem in the login code

 
0
  #4
Feb 16th, 2009
@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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: problem in the login code

 
0
  #5
Feb 17th, 2009
Rewrite your catch block like this and let me know what message u get on the label

  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.  
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC