locked
CSS Friendly error RRS feed

  • Question

  • User1894305733 posted

    Hi not sure if I should be posting this here but this is my problem.

     

    Downloaded the files today had a little play and they work fine for login control and login status rendering css code. The problem I have is that I now get an error when logging into my app. This is the code where it falls down:

     

    1            Public Overrides Function GetUser( _
    2            ByVal username As String, _
    3            ByVal userIsOnline As Boolean _
    4            ) _
    5            As MembershipUser
    6    
    7                Dim _sqlConnection As SqlConnection = New SqlConnection(_sqlConnectionString)
    8                Dim _sqlCommand As SqlCommand = New SqlCommand("User_Sel", _sqlConnection)
    9    
    10               _sqlCommand.CommandType = CommandType.StoredProcedure
    11               _sqlCommand.Parameters.Add("@username", SqlDbType.NVarChar, 255).Value = username
    12               _sqlCommand.Parameters.Add("@applicationName", SqlDbType.NVarChar, 255).Value = _applicationName
    13   
    14               Dim _membershipUser As MembershipUser = Nothing
    15               Dim _sqlDataReader As SqlDataReader = Nothing
    16   
    17               Try
    18                   _sqlConnection.Open()
    19   
    20                   _sqlDataReader = _sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
    21   
    22                   If _sqlDataReader.HasRows Then
    23                       _sqlDataReader.Read()
    24                       _membershipUser = GetUserFromReader(_sqlDataReader)
    25   
    26                       If userIsOnline Then
    27                           Dim _sqlUpdateCommand As SqlCommand = New SqlCommand("User_UpdateActivityDate_ByUserName", _sqlConnection)
    28   
    29                           _sqlUpdateCommand.CommandType = CommandType.StoredProcedure
    30                           _sqlUpdateCommand.Parameters.Add("@username", SqlDbType.NVarChar, 255).Value = username
    31                           _sqlUpdateCommand.Parameters.Add("@applicationName", SqlDbType.NVarChar, 255).Value = _applicationName
    32                           _sqlUpdateCommand.ExecuteNonQuery()
    33                       End If
    34                   End If
    35               Catch e As SqlException
    36                   'Add exception handling here.
    37               Finally
    38                   If Not _sqlDataReader Is Nothing Then _sqlDataReader.Close()
    39               End Try
    40   
    41               Return _membershipUser
    42           End Function
    

     

    line 32 is where it breaks and i get the following error:

    System.InvalidOperationException was unhandled by user code
      Message="There is already an open DataReader associated with this Command which must be closed first."
      Source="System.Data"
      StackTrace:
           at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
           at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
           at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
           at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
           at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
           at Sleuth2.CustomMembershipProvider.GetUser(String username, Boolean userIsOnline) in C:\Users\Tuppers\..\MembershipProvider.vb:line 594
           at System.Web.Security.Membership.GetUser(String username, Boolean userIsOnline)
           at System.Web.Security.Membership.GetUser()
           at CSSFriendly.LoginStatusAdapter.RenderContents(HtmlTextWriter writer)
           at System.Web.UI.WebControls.Adapters.WebControlAdapter.Render(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
           at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
           at System.Web.UI.Control.Render(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
           at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
           at System.Web.UI.WebControls.LoginView.Render(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
           at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
           at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
           at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
           at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
           at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
           at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
           at System.Web.UI.Control.Render(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
           at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
           at System.Web.UI.Page.Render(HtmlTextWriter writer)
           at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
           at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:
     

    now if I exclude the .browser file from the project obviously the CSS Friendly stuff stops but the login works???? So I am not sure how to get around this or am I just an unlucky one that has to forget these adapters?

     Thanks in advance

    Tuppers

    Friday, May 15, 2009 1:02 PM

All replies

  • User1470709927 posted

    Hi there, at line 27 you are trying to declare a new sqlcommand using the same sqlconnection that you used for the sqldatareader.  The problem is that the sqlconnection is still in use because you haven't closed the sqldatareader yet.

    If you close the sqldatareader on line 25 after you pass the user info to the _membershipUser then it should work.

    Or for some reason if you need the sqldatareader to stay open then create another sqlconnection for the updatecommand.

    Hope this helps,

    Saturday, May 16, 2009 2:45 PM
  • User1894305733 posted
    Thanks for the reply!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>Well I was looking into that but I do not understand why the code works perfectly when the CSS Friendly suite is not hooked up to the site! It’s strange!<o:p></o:p>I am in the process of using their code and adding slowly but surely bits and bobs to render the controls in divs I have managed to complete the Login and Login Status Control with no hiccup so far!<o:p></o:p>If I do figure it out I will post later!<o:p></o:p><o:p>Thanks again Tuppers</o:p>
    Sunday, May 17, 2009 2:35 PM