473,287 Members | 1,616 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,287 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 2419
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.