473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Login.aspx??? Error

Sam
I'm trying to create authentication for username and password but encounter
below error message:

Error Message
-----------------------
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 20:
Line 21: Try
Line 22: con.Open()
Line 23:
Line 24: Dim rd as SqlDataReader = cmd.ExecuteReader()

Source File: C:\JDE_Archival\authentication.aspx Line: 22

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been
initialized.]
System.Data.SqlClient.SqlConnection.Open() +809
ASP.authentication_aspx.authenticate(Object Sender, EventArgs e) in
C:\JDE_Archival\authentication.aspx:22
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263

Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET
Version:1.0.3705.0
Coding ASP.Net
-----------------------
Sub authenticate(Sender as Object, e As EventArgs)
Dim con As New
SqlConnection(ConfigurationSettings.AppSettings("c onstring"))

Dim cmd as New SqlCommand()
cmd.CommandText = "Select * from authentication where username ='"
& txtUsername.Text & "'"
cmd.Connection = con

Try
con.Open()

Dim rd as SqlDataReader = cmd.ExecuteReader()

While rd.read()
If rd("password").ToString = txtPassword.Text Then
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text,
false)
Else
Response.Redirect("http://localhost/warning.aspx")
End If
End While

rd.Close()

Finally
con.Close()
End Try
End Sub
Nov 18 '05 #1
2 2421
Your code is fine (although see the following note), so you might want to
check that ConfigurationSettings.AppSettings("constring") is actually
returning what you expect it to...my guess is it isn't.

Your code is open to a pretty _huge_ SQL Injection attack. This type of
code will be the death of your application:
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Sam" <cy********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm trying to create authentication for username and password but encounter below error message:

Error Message
-----------------------
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 20:
Line 21: Try
Line 22: con.Open()
Line 23:
Line 24: Dim rd as SqlDataReader = cmd.ExecuteReader()

Source File: C:\JDE_Archival\authentication.aspx Line: 22

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been
initialized.]
System.Data.SqlClient.SqlConnection.Open() +809
ASP.authentication_aspx.authenticate(Object Sender, EventArgs e) in
C:\JDE_Archival\authentication.aspx:22
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263

Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET Version:1.0.3705.0
Coding ASP.Net
-----------------------
Sub authenticate(Sender as Object, e As EventArgs)
Dim con As New
SqlConnection(ConfigurationSettings.AppSettings("c onstring"))

Dim cmd as New SqlCommand()
cmd.CommandText = "Select * from authentication where username ='" & txtUsername.Text & "'"
cmd.Connection = con

Try
con.Open()

Dim rd as SqlDataReader = cmd.ExecuteReader()

While rd.read()
If rd("password").ToString = txtPassword.Text Then
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false)
Else
Response.Redirect("http://localhost/warning.aspx")
End If
End While

rd.Close()

Finally
con.Close()
End Try
End Sub

Nov 18 '05 #2
oopppss...sent that a little too quickly.

Anyways, this code:
Select * from authentication where username ='" & txtUsername.Text & "'"

will be the death of you, consider replacing that with parameterized
properties:

cmd.CommandText = "Select * from authentication where username = @UserName"
cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value =
txtUsername.Text

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Sam" <cy********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm trying to create authentication for username and password but encounter below error message:

Error Message
-----------------------
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.

Source Error:
Line 20:
Line 21: Try
Line 22: con.Open()
Line 23:
Line 24: Dim rd as SqlDataReader = cmd.ExecuteReader()

Source File: C:\JDE_Archival\authentication.aspx Line: 22

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been
initialized.]
System.Data.SqlClient.SqlConnection.Open() +809
ASP.authentication_aspx.authenticate(Object Sender, EventArgs e) in
C:\JDE_Archival\authentication.aspx:22
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263

Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET Version:1.0.3705.0
Coding ASP.Net
-----------------------
Sub authenticate(Sender as Object, e As EventArgs)
Dim con As New
SqlConnection(ConfigurationSettings.AppSettings("c onstring"))

Dim cmd as New SqlCommand()
cmd.CommandText = "Select * from authentication where username ='" & txtUsername.Text & "'"
cmd.Connection = con

Try
con.Open()

Dim rd as SqlDataReader = cmd.ExecuteReader()

While rd.read()
If rd("password").ToString = txtPassword.Text Then
FormsAuthentication.RedirectFromLoginPage(txtUsern ame.Text, false)
Else
Response.Redirect("http://localhost/warning.aspx")
End If
End While

rd.Close()

Finally
con.Close()
End Try
End Sub

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stu | last post by:
Hi All, I have an ASP.NET application to which I have implemented forms authentication to handle security. It is a relatively straight forward solution with all aspx pages residing in the root...
1
by: Philippe Meunier | last post by:
My web.config looks like this concerning login : <authentication mode="Forms"> <forms loginUrl="frmLogin.aspx" timeout="20" /> </authentication> <authorization>
4
by: SB | last post by:
Hi I'm trying to get forms-based authentication to authenticate different users for differet pages, like this: <configuration> <location path="Member" allowOverride="true"> <system.web>...
2
by: Assimalyst | last post by:
Hi, I am creating a website where i want to allow some webforms to be accessible to all users, and those in a subdirectory available only to authenticated users. I have created a script to...
1
by: frekster | last post by:
All, Windows xp pro box with vs 2003 and .net 1.1 installed. Downloaded a project from source safe via vpn to my ome pc to work from home. I have three other projects on my pc that works fine...
6
by: Tim Cartwright | last post by:
I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web...
1
by: rh | last post by:
In my web.config file, I added code so that users will be redirected to 1 of 2 Login pages depending on the original page they are trying to access. However, I get the following error message: ...
0
by: muder | last post by:
I have a standard Login ASP.NET 2.0 control on a login Page, a LoginName and LoginStatus controls on the member's page. once the user login successfully I am redirecting the user to Member.aspx...
4
by: Ben | last post by:
Hi, I defined roles in order to deny access for some pages to anonymous users. I tested it by typing the url of a denied page to test the system (http://denypage.aspx). It works (access...
0
by: sandari | last post by:
The following code (web.config in Visual Studio 2005) is supposed to redirect a user to the appropriate Form depending on their role. However, regardless of the user's role, the only page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.