Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute reader error - urgent plz

Status
Not open for further replies.

lee2k

Programmer
Aug 19, 2001
28
0
0
IN
hi,
if i run the aspx file i get the following error:

"ExecuteReader requires an open and available Connection. The connection's current state is Closed.".

i didnt use ExecuteReader anywhere in the coding. actually im using 3 files to validate the username and the password of the user. please let me know how to validate the data with the database value. if the username is true i want to redirect to another aspx file, otherwise i must show an error message in the login file.

the codings are:

-------------login.aspx-------------
<%@ Page Language=&quot;vb&quot; Codebehind=&quot;Login.aspx.vb&quot; AutoEventWireup=&quot;false&quot; Inherits=&quot;shopping.WebForm1&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<title>Login Form</title>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio.NET 7.0&quot;>
<meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic 7.0&quot;>
<meta name=&quot;vs_defaultClientScript&quot; content=&quot;JavaScript&quot;>
<meta name=&quot;vs_targetSchema&quot; content=&quot; </HEAD>
<body>
<form runat=&quot;server&quot;>
<asp:Label id=&quot;lblMessage&quot; runat=&quot;server&quot; />
<br>
<br>
<asp:Label ID=&quot;lblUserName&quot; Runat=&quot;server&quot; text=&quot;Enter User Name&quot; />
<asp:TextBox ID=&quot;txtUserName&quot; MaxLength=&quot;10&quot; TextMode=&quot;SingleLine&quot; Runat=&quot;server&quot; />
<br>
<asp:Label ID=&quot;lblPassword&quot; Runat=&quot;server&quot; text=&quot;Enter Password&quot; />
<asp:TextBox ID=&quot;txtPassword&quot; MaxLength=&quot;10&quot; TextMode=&quot;Password&quot; Runat=&quot;server&quot; />
<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:ImageButton id=&quot;LoginBtn&quot; ImageURL=&quot;images/signin.gif&quot; runat=&quot;server&quot; />
<br>
<br>
<br>
</form>
</body>
</HTML>




-------------------login.aspx.vb---------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Security

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents lblUserName As System.Web.UI.WebControls.Label
Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
Protected WithEvents lblPassword As System.Web.UI.WebControls.Label
Protected WithEvents LoginBtn As System.Web.UI.WebControls.ImageButton
Protected WithEvents Message As System.Web.UI.WebControls.Label
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox

#Region &quot; Web Form Designer Generated Code &quot;

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub New()

End Sub

Private Sub LoginBtn_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles LoginBtn.Click
Dim mycomponent As shopping.CustomersDB = New shopping.CustomersDB()
Dim custid As String = mycomponent.Login(txtUserName.Text, txtPassword.Text)
If custid = &quot;&quot; Then
txtMessage.Text = &quot;Login Failed&quot;
Else
txtMessage.Text = &quot;Login Success&quot;
End If
End Sub
End Class






-----customer.vb-------
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Namespace shopping

Public Class CustomersDB

Public Function Login(ByVal UserName As String, ByVal Password As String) As String
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings(&quot;ConnectionString&quot;))
Dim myCommand As SqlCommand = New SqlCommand(&quot;CustomerLogin&quot;, myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Dim parUserName As SqlParameter = New SqlParameter(&quot;@UserName&quot;, SqlDbType.NVarChar, 10)
parUserName.Value = UserName
myCommand.Parameters.Add(parUserName)
Dim parUserPass As SqlParameter = New SqlParameter(&quot;@UserPass&quot;, SqlDbType.NVarChar, 10)
parUserPass.Value = Password
myCommand.Parameters.Add(parUserPass)
Dim parameterCustomerID As SqlParameter = New SqlParameter(&quot;@CustomerID&quot;, SqlDbType.NVarChar, 10)
parameterCustomerID.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterCustomerID)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Dim customerId As String = parameterCustomerID.Value
If customerId = &quot;&quot; Then
Return Nothing
Else
Return customerId
End If
End Function

End Class

End Namespace
 
The extended error message will give you a line number, and a file name. Go to the line number it gives you in the file it specifies. There you will find what you seek.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Not completely sure, but I would try changing this:
Code:
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Dim customerId As String = parameterCustomerID.Value

To this:
Code:
myConnection.Open()
myCommand.ExecuteNonQuery()
Dim customerId As String = parameterCustomerID.Value
myConnection.Close()

While the connection is open assign the String it's value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top