Simple ASP.Net Login Page using C#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #11
Jul 19th, 2005
Are those lines in web.confg? Using system; should not be in the Web.Config file.

Remove that using system line

Provide some of the code giving you the issue.

Thanks
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: false420 is an unknown quantity at this point 
Solved Threads: 0
false420 false420 is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #12
Jul 19th, 2005
using System;
<?xml version="1.0" encoding="utf-8" ?>

<configuration>
<appSettings>
<add key="strConn" value="Data Source=(local);database=LoginTest;User id=#;Password=#;"/>
</appSettings>

<system.web>


i know it seemed wierd to me cuz usually you have to compile hings with using statements. im new so i wasnt sure. i had just copied yours up top and inserted my stuff
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: false420 is an unknown quantity at this point 
Solved Threads: 0
false420 false420 is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #13
Jul 19th, 2005
ive edited it to this:

<configuration>
<appSettings>
<add key="strConn" value="Data Source=(local);database=LoginTest;User id=#;Password=#;"/>
</appSettings>
</configuration>


and it works but for some reason i get this but there is no northwind stuff anywhere.

System.Data.SqlClient.SqlException: Invalid object name 'NorthWindUsers'. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at login.WebForm1.DBConnection(String txtUser, String txtPass)Error Connecting to the database
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #14
Jul 19th, 2005
Ok, my bad. Sorry about that. See... even I goof on copy paste. Hehe. But that doesn't excuse you... See, you should understand what you are copying and pasting. :lol: :lol:

Saying that. You are sure your SQL Db has the NorthWindUsers Table created? Because the error message is saying that you don't.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: false420 is an unknown quantity at this point 
Solved Threads: 0
false420 false420 is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #15
Jul 20th, 2005
now i see where im getting hung up at. i can understand the code pretty well but i cant figure out why my stored procedure is telling me that the @username and @password is invalid columns, i thought thats where it does the match from the entered data.
SELECT COUNT(*) AS Num_of_User
FROM tblUser
WHERE (((tblUser.U_Name)=[@UserName]) AND ((tblUser.U_Password)=[@Password]));

im just messing around with it to help me get better with .net
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: false420 is an unknown quantity at this point 
Solved Threads: 0
false420 false420 is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #16
Jul 20th, 2005
it will also tell me i must declare the username and password variables in the stored procedures, ive never really worked with strored procedures before
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 2
Reputation: warchild is an unknown quantity at this point 
Solved Threads: 0
warchild warchild is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #17
Sep 25th, 2005
I've converted the code to OleDb but I keep getting this error message:

System.Data.OleDb.OleDbException: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done. at System.Data.OleDb.OleDbCommand.ProcessResults(Int32 hr) at System.Data.OleDb.OleDbCommand.ApplyAccessor(Int32 count, DBBindings bindings) at System.Data.OleDb.OleDbCommand.CreateAccessor() at System.Data.OleDb.OleDbCommand.InitializeCommand(CommandBehavior behavior, Boolean throwifnotsupported) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at TrackMyFood.uLogin.DBConnection(String txtUser, String txtPass) in c:\inetpub\wwwroot\trackmyfood\ulogin.aspx.cs:line


And here is my code:
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Web.Security;
  12. using System.Data.SqlClient;
  13. using System.Data.OleDb;
  14. using System.Configuration;
  15.  
  16. namespace TrackMyFood
  17. {
  18. /// <summary>
  19. /// Summary description for WebForm1.
  20. /// </summary>
  21. public class uLogin : System.Web.UI.Page
  22. {
  23. protected System.Web.UI.WebControls.TextBox txtUserName;
  24. protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
  25. protected System.Web.UI.WebControls.TextBox txtPassword;
  26. protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
  27. protected System.Web.UI.WebControls.Button cmdSubmit;
  28. protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
  29. protected System.Web.UI.WebControls.Label lblMessage;
  30. protected System.Web.UI.WebControls.Label lblMessage2;
  31.  
  32. private void Page_Load(object sender, System.EventArgs e)
  33. {
  34. // Put user code to initialize the page here
  35. }
  36.  
  37. #region Web Form Designer generated code
  38. override protected void OnInit(EventArgs e)
  39. {
  40. //
  41. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  42. //
  43. InitializeComponent();
  44. base.OnInit(e);
  45. }
  46.  
  47. /// <summary>
  48. /// Required method for Designer support - do not modify
  49. /// the contents of this method with the code editor.
  50. /// </summary>
  51. private void InitializeComponent()
  52. {
  53. this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
  54. this.Load += new System.EventHandler(this.Page_Load);
  55.  
  56. }
  57. #endregion
  58.  
  59. private void cmdSubmit_Click(object sender, System.EventArgs e)
  60. {
  61. if (Page.IsValid)
  62. {
  63. if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim()))
  64. {
  65. FormsAuthentication.RedirectFromLoginPage (txtUserName.Text, false);
  66. }
  67. else
  68. {
  69. lblMessage.Text = "Invalid Login, please try again!";
  70. }
  71. }
  72.  
  73. }
  74. private bool DBConnection(string txtUser, string txtPass)
  75. {
  76. OleDbConnection myConn = new OleDbConnection(ConfigurationSettings.AppSettings["Nutrition"]);
  77. OleDbCommand myCmd = new OleDbCommand("sp_ValidateUser", myConn);
  78. myCmd.CommandType = CommandType.StoredProcedure;
  79.  
  80. OleDbParameter objParam1;
  81. OleDbParameter objParam2;
  82. OleDbParameter returnParam;
  83.  
  84. objParam1 = myCmd.Parameters.Add ("@UserName", OleDbType.Char);
  85. objParam2 = myCmd.Parameters.Add ("@Password", OleDbType.Char);
  86. returnParam = myCmd.Parameters.Add ("@Num_of_User", OleDbType.Integer);
  87.  
  88. objParam1.Direction = ParameterDirection.Input;
  89. objParam2.Direction = ParameterDirection.Input;
  90. returnParam.Direction = ParameterDirection.ReturnValue;
  91.  
  92. objParam1.Value = txtUser;
  93. objParam2.Value = txtPass;
  94.  
  95. try
  96. {
  97. if (myConn.State.Equals(ConnectionState.Closed))
  98. {
  99. myConn.Open();
  100. myCmd.ExecuteNonQuery();
  101. }
  102. if ((int)returnParam.Value < 1)
  103. {
  104. lblMessage.Text = "Invalid Login!";
  105. return false;
  106. }
  107. else
  108. {
  109. myConn.Close();
  110. return true;
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. lblMessage2.Text = ex + "Error Connecting to the database";
  116. return false;
  117. }
  118.  
  119. }
  120. }
  121. }
Please help! Thanks. W
Last edited by Paladine; Sep 26th, 2005 at 3:08 pm. Reason: PLEASE USE [CODE][/CODE] when posting code!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #18
Sep 26th, 2005
OK a don't see anything wrong with your code, what version of SQL server are you using? Microsoft Recommends that if you have version 7.0 or later (includes MSDE) the SqlClient should be used.

But also inorder to use OleDB you need to consider this: The .NET Framework Data Provider for OLE DB requires the installation of MDAC 2.6 or later.

Not sure if that helps much, but have you tried making any other connections to the SQL Server using OleDb? Also, have you tried removing the using System.Data.SqlClient and recompiling and see what happens? I know it sounds strange and too simplistic, but stranger things have happened that can make an application run.

Hope this helps.

P.S. When does this error occur? OnCompile? Provide as much details as you can on the sequence that generates this message.
Last edited by Paladine; Sep 26th, 2005 at 3:09 pm. Reason: Another question?
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 2
Reputation: warchild is an unknown quantity at this point 
Solved Threads: 0
warchild warchild is offline Offline
Newbie Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #19
Sep 26th, 2005
My apologies, I should have mentioned it earlier...

I'm using an Access Database and I'm running the StoredProcedure from your VB.Net example.
  1. SELECT COUNT(*) AS Num_of_User
  2. FROM tblUser
  3. WHERE (((tblUser.U_Name)=[@UserName]) AND ((tblUser.U_Password)=[@Password]));

The Access table is as follows:
u_ID - Autonumber
u_Name - Text
u_Password - Text


The application builds and compiles. The error occurs when the cmdsubmit is called, which calls the DBConnection. Specifically, it errors on the ExecuteNonQuery.
  1. myCmd.ExecuteNonQuery();

Thanks again for the help! W.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Simple ASP.Net Login Page using C#

 
0
  #20
Sep 27th, 2005
Hmm, I would check the security settings on your Access DB.

I can't see anything wrong with the code... hmm

I will look into it again tomorrow!
Originally Posted by warchild
My apologies, I should have mentioned it earlier...

I'm using an Access Database and I'm running the StoredProcedure from your VB.Net example.
  1. SELECT COUNT(*) AS Num_of_User
  2. FROM tblUser
  3. WHERE (((tblUser.U_Name)=[@UserName]) AND ((tblUser.U_Password)=[@Password]));

The Access table is as follows:
u_ID - Autonumber
u_Name - Text
u_Password - Text


The application builds and compiles. The error occurs when the cmdsubmit is called, which calls the DBConnection. Specifically, it errors on the ExecuteNonQuery.
  1. myCmd.ExecuteNonQuery();

Thanks again for the help! W.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC