| | |
Simple ASP.Net Login Page using C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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
Remove that using system line
Provide some of the code giving you the issue.
Thanks
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
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
<?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
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
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
<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
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.
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.
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Sep 2005
Posts: 2
Reputation:
Solved Threads: 0
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:
Please help! Thanks. W
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:
C# Syntax (Toggle Plain Text)
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Web.Security; using System.Data.SqlClient; using System.Data.OleDb; using System.Configuration; namespace TrackMyFood { /// <summary> /// Summary description for WebForm1. /// </summary> public class uLogin : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox txtUserName; protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator; protected System.Web.UI.WebControls.TextBox txtPassword; protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator; protected System.Web.UI.WebControls.Button cmdSubmit; protected System.Web.UI.WebControls.ValidationSummary Validationsummary1; protected System.Web.UI.WebControls.Label lblMessage; protected System.Web.UI.WebControls.Label lblMessage2; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void cmdSubmit_Click(object sender, System.EventArgs e) { if (Page.IsValid) { if (DBConnection(txtUserName.Text.Trim(), txtPassword.Text.Trim())) { FormsAuthentication.RedirectFromLoginPage (txtUserName.Text, false); } else { lblMessage.Text = "Invalid Login, please try again!"; } } } private bool DBConnection(string txtUser, string txtPass) { OleDbConnection myConn = new OleDbConnection(ConfigurationSettings.AppSettings["Nutrition"]); OleDbCommand myCmd = new OleDbCommand("sp_ValidateUser", myConn); myCmd.CommandType = CommandType.StoredProcedure; OleDbParameter objParam1; OleDbParameter objParam2; OleDbParameter returnParam; objParam1 = myCmd.Parameters.Add ("@UserName", OleDbType.Char); objParam2 = myCmd.Parameters.Add ("@Password", OleDbType.Char); returnParam = myCmd.Parameters.Add ("@Num_of_User", OleDbType.Integer); objParam1.Direction = ParameterDirection.Input; objParam2.Direction = ParameterDirection.Input; returnParam.Direction = ParameterDirection.ReturnValue; objParam1.Value = txtUser; objParam2.Value = txtPass; try { if (myConn.State.Equals(ConnectionState.Closed)) { myConn.Open(); myCmd.ExecuteNonQuery(); } if ((int)returnParam.Value < 1) { lblMessage.Text = "Invalid Login!"; return false; } else { myConn.Close(); return true; } } catch (Exception ex) { lblMessage2.Text = ex + "Error Connecting to the database"; return false; } } } }
Last edited by Paladine; Sep 26th, 2005 at 3:08 pm. Reason: PLEASE USE [CODE][/CODE] when posting code!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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.
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?
•
•
Join Date: Sep 2005
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
Thanks again for the help! W.
I'm using an Access Database and I'm running the StoredProcedure from your VB.Net example.
C# Syntax (Toggle Plain Text)
SELECT COUNT(*) AS Num_of_User FROM tblUser 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.
C# Syntax (Toggle Plain Text)
myCmd.ExecuteNonQuery();
Thanks again for the help! W.
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!
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.
C# Syntax (Toggle Plain Text)
SELECT COUNT(*) AS Num_of_User FROM tblUser 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.
C# Syntax (Toggle Plain Text)
myCmd.ExecuteNonQuery();
Thanks again for the help! W.
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: C# online resources, help and advice?
- Next Thread: DataGridView with List In Object to Display
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql nargalax networking object operator path photoshop picturebox pixelinversion polynomial post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





