.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #16  
Old April 16th, 2008, 02:57 PM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
There is already an open DataReader associated with this Command which must be closed first.

Line 30: lblName.Text = sqlNameCommand1.ExecuteScalar.ToString()

[COLOR=Black]What does this mean?

Reply With Quote
  #17  
Old April 16th, 2008, 03:04 PM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,457 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 27 m 57 sec
Reputation Power: 519
Not to be flip, but exactly what it says. I'm guessing you may have forgotten to close the connection or trying to do the ExecuteReader whilst doing something else with the connection. Would need the surrounding code to tell.

BTW sqlNameCommand1.ExeucteScalar.ToString() is a VERY BAD thing to do (for a SELECT query anyway). If the command doesn't return any rows, it will return Nothing, and invoking a method on Nothing will cause an exception.
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. Not FDIC insured

Reply With Quote
  #18  
Old April 16th, 2008, 03:05 PM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
Code:
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
   
		Dim sqlConnect As System.Data.SqlClient.SqlConnection
		Dim sqlCommandDB As System.Data.SqlClient.SqlCommand
		Dim customerName As String
		Dim obj As Object
		   
		sqlConnect = New System.Data.SqlClient.SqlConnection("DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDire  ctory|\MediaDirect.mdf;Integrated Security=True;User Instance=True")
   
		sqlCommandDB = New System.Data.SqlClient.SqlCommand("SELECT [name] FROM [Customer] WHERE [Username] = '" & txtUserName.Text & "' AND [Password] = '" & txtPassword.Text & "'")
	   
		Try
			sqlConnect.Open()
			obj = sqlCommandDB.ExecuteScalar
			If (obj = Nothing) Then
				lblError.Text = "Invalid Userid Or Password"
				lblError.ForeColor = Drawing.Color.Red
				lblName.Text = String.Empty
			Else
				lblName.Text = String.Format("Welcome {0} To Media Direct", Convert.ToString(obj))
				lblError.Text = String.Empty
			End If
		Catch ex As Exception
			lblError.Text = "Oops, something bad happened, call the administrator"
		Finally
			sqlConnect.Close()

Reply With Quote
  #19  
Old April 16th, 2008, 03:14 PM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,457 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 27 m 57 sec
Reputation Power: 519
So, exactly where in the code you posted is the line causing the error? The line you posted isn't in there.

Reply With Quote
  #20  
Old April 16th, 2008, 03:21 PM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
thats strange when i run the code i get this error but when i check the code the lines is not there

Reply With Quote
  #21  
Old April 16th, 2008, 03:35 PM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
the error message is coming from this souce file Default.aspx.vb. how do i update this file

Reply With Quote
  #22  
Old April 16th, 2008, 03:40 PM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,457 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 27 m 57 sec
Reputation Power: 519
Aha! So VWD has code-behinds. Don't know in VWD, but in Visual Studio F7 opens the code-behind page.

Reply With Quote
  #23  
Old April 16th, 2008, 03:43 PM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
i open it and copied the code into their.
but the log in still doest work

Reply With Quote
  #24  
Old April 17th, 2008, 02:47 AM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
i tried the code you provided
Code:
  Protected Sub btnButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

  

  		  Dim sqlConnect As System.Data.SqlClient.SqlConnection

  		  Dim sqlCommandDB As System.Data.sqlClient.sqlCommand

  		  Dim customerName as String

  		  Dim obj as Object

  

  		sqlConnect = New System.Data.SqlClient.SqlConnection(Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector    y|\MediaDirect.mdf;Integrated Security=True;User Instance=True")

  

  		sqlCommandDB = New System.Data.SqlClient.SqlConnection("SELECT [name] FROM [Customer] WHERE [Username] = '" txtUsername.Text & "' AND [Password] = '" txtPassword.Text & "'")

  

  		Try

  			sqlConnect.Open()

  			obj = sqlCommandDB.ExecuteScalar

  			If (obj = Nothing) Then

  			  lblError.Text = "Invalid Userid Or Password"

  			  lblError.ForeColor = Drawing.Color.Red

  			  lblName.Text = String.Empty

  			  dataCustomer.Visible = False

  			Else

  			  lblName.Text = String.Format("Welcome {0} To Media Direct", Convert.ToString(obj))

  			dataCustomer.Visible = True

  			  lblError.Text = String.Empty

  		  End If

  		Catch ex as Exception

  		  lblError.Text = "Oops, something bad happened, call the administrator"

  		Finally

  		  sqlConnect.Close()

  		End Try

  	  End Sub  

  


it works but everytime i tried to login it displays "Oops, something bad happened, call the administrator" instead of the welcome note and their userid

Reply With Quote
  #25  
Old April 17th, 2008, 08:22 AM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,457 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 27 m 57 sec
Reputation Power: 519
Then something in the Try block is throwing an exception. To be honest, I probably put too much in the Try block -- the If..Then..Else should probably be outside.

Anyway put this into your Catch block rather than the cutesy message I provided:
lblError.Text = ex.Message

Reply With Quote
  #26  
Old April 18th, 2008, 08:25 AM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
any idea of what i should put in and where

Reply With Quote
  #27  
Old April 18th, 2008, 08:56 AM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,457 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 27 m 57 sec
Reputation Power: 519
As I said, replace the 1 line of code in the Catch block with the 1 I provided.

Magic, I perceive that you are not much beyond the 'Hello World' stage in your ASP.NET development. I'm not trying to slam you here, but I think spending some time with the ASP.NET tutorials found lurking here an elsewhere on the web would pay off in the long run. Taking a look here would be a good place to start. Sure, we'll help you get past you current sticking spot, and we're here if you have any questions, of course.

Reply With Quote
  #28  
Old April 19th, 2008, 03:35 AM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
i understood what u said and did that. the probelm was i copied it into the wrong file that i had backup. i really appreite your help.

Reply With Quote
  #29  
Old April 30th, 2008, 01:34 PM
magic30 magic30 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 18 magic30 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 45 m 25 sec
Reputation Power: 0
ive made alot changes and now need to know how to add a logout button once the user is login. is there a way to change the button once the user is login.

Reply With Quote
  #30  
Old April 30th, 2008, 01:42 PM
Wolffy's Avatar
Wolffy Wolffy is offline
Slaprentice of Wolves
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Aug 2007
Location: Mossville, IL
Posts: 1,457 Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level)Wolffy User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 27 m 57 sec
Reputation Power: 519
Changing the text of a button is easy enough -- it has a Text property too. Curious tho what you expect to do during the logoff process?

Reply With Quote