« Previous Next »

Thread: Errors In ASP .NET App

Last post 07-14-2009 2:25 PM by tomkmvp. 9 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (10 items)

Sort Posts:

  • 07-13-2009, 11:07 AM

    • dsheldon
    • Not Ranked
    • Joined on 07-13-2009, 2:43 PM
    • Posts 7

    Errors In ASP .NET App

    I am having a problem in an ASP .NET application that we are finishing up that is only now rearing it's ugly head. We have deployed the app to several departments for testing and now that there are multiple users on the system strange things are happening.

    The app is running in IIS 6 on a Windows 2003 server. It was developed in Visual Studio 2008 targetting .NET 3.5. There is a login form that prepopulates with an employee number determined by the Windows user that is accessing the site. We have a centralized employee database that is a combination of AD information and employee data from our Accounting package and we tie into it using the Windows login account. IIS and SQL are on the same server and the IIIS App Pool that this application uses runs under the context of a domain account that has been assigned the dbo role on the database. I have even tried other IIS servers and other SQL boxes for the database.

    Anyway, if only 1 person accesses the site at a time it works great. As soon as a second person logs in we start seeing errors appear. Most of them appear to be related to code that manipulates SQL data(ie 'Table 0 does not exist' or 'Column or property EmployeeID does not belong to table Table'). We also noticed that if there are multiple users, when a user opens the login form, the employee number that is prepopulated will be the number of the employee that accessed the form before them.

    Like I said, we have moved the app and database to differrent servers with no luck. I know that this is not an issue with the code. It works fine in development and when used by only 1 user, but anything past that and it goes nuts. I have turned off our antivirus software, changed the App Pool, changed the identity that the App Pool runs under and republished multiple times but I feel like I'm spinning my wheels. I don't know if this is an issue with ASP .NET state management or if there is a limit on the number of allowed connections somewhere or what the problem may be, but it sure is giving us fits. Any help that you could give would be greatly appreciated!!

  • 07-13-2009, 11:31 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,238
    • IIS MVPs

    Re: Errors In ASP .NET App

    dsheldon:
    I know that this is not an issue with the code.

    I'm not so sure of that.

    dsheldon:
    We also noticed that if there are multiple users, when a user opens the login form, the employee number that is prepopulated will be the number of the employee that accessed the form before them.

    Please share this code.

  • 07-13-2009, 11:41 AM In reply to

    • dsheldon
    • Not Ranked
    • Joined on 07-13-2009, 2:43 PM
    • Posts 7

    Re: Errors In ASP .NET App

    Below is the code that fills the employee number text box. It is very simple code and really leaves no room for error. Thanks for your help.

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

    'FILL THE EMPLOYEE NUMBER BOX WITH THE EMPLOYEE LOGGED IN TO THE PC

    Try

    Dim user As String = HttpContext.Current.User.Identity.Name.ToString()

    If user.IndexOf("\") >= 0 Then

    user = user.Substring(user.IndexOf("\") + 1, user.Length - user.IndexOf("\") - 1)

    End If

    If user <> "" And Not user = Nothing Then

    Try

    'GET THE EMPLOYEE'S ID NUMBER FROM THE EMPLOYEE DATABASE

    Dim da As New SqlDataAdapter("SELECT EmployeeID FROM Employee.dbo.tblEmployee WHERE UserName = @User", cnn)

    da.SelectCommand.CommandType = CommandType.Text

    da.SelectCommand.Parameters.AddWithValue(
    "@User", user)

    Dim ds As New DataSet

    If Not cnn.State = ConnectionState.Open Then cnn.Open()

    da.Fill(ds)

    If ds.Tables(0).Rows.Count > 0 Then

    txtEmpNumber.Text = ds.Tables(0).Rows(0).Item("EmployeeID").ToString

    txtPassword.Focus()

    Else

    txtEmpNumber.Focus()

    End If

    Catch ex As Exception

    lblError.Text = ex.Message ' & vbNewLine & ex.StackTrace

    lblError.Visible = True

    Finally

    cnn.Close()

    End Try

    End If

     

    Catch ex As Exception

    txtEmpNumber.Text = ""

    End Try

    End Sub

  • 07-13-2009, 12:58 PM In reply to

    Re: Errors In ASP .NET App

    dsheldon:
    We also noticed that if there are multiple users, when a user opens the login form, the employee number that is prepopulated will be the number of the employee that accessed the form before them.
     

    That sounds like the user is being allocated the session of the previously logged-on user. How does this application manage session state exactly ?

    Paul Lynch | www.iisadmin.co.uk
  • 07-13-2009, 1:42 PM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,238
    • IIS MVPs

    Re: Errors In ASP .NET App

    dsheldon:
    If Not cnn.State = ConnectionState.Open Then cnn.Open()

    Hmm ... where does cnn get initialized?  Does the porblem go away if you remove the "if then" logic and just open the connection everytime?

  • 07-13-2009, 2:23 PM In reply to

    • dsheldon
    • Not Ranked
    • Joined on 07-13-2009, 2:43 PM
    • Posts 7

    Re: Errors In ASP .NET App

    Below is the code for initializing cnn. This is done in a module. I wonder if you may be on to something there. This is my first ASP .NET app and as I am used to Windows forms development I never had to worry about session state and static variables.(Listen to me all full of excuses hey?? :-) Anyway, my question is ' Does ASP .NET handle anything coded in modules as static code?'. If so , I think I have my answer. Thanks to tomkmvp and Paul Lynch for the help.

     

    Friend cnn As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

  • 07-13-2009, 3:01 PM In reply to

    Re: Errors In ASP .NET App

  • 07-13-2009, 3:13 PM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,238
    • IIS MVPs

    Re: Errors In ASP .NET App

    It's not so much about modules and session state as it is about connections.  Does the problem go away if you remove that bit of connection checking logic?  Seems to me like the  connection is held open between requests and it's preserving the data from previous requests.

    See also http://forums.asp.net/ ...

  • 07-14-2009, 2:17 PM In reply to

    • dsheldon
    • Not Ranked
    • Joined on 07-13-2009, 2:43 PM
    • Posts 7

    Re: Errors In ASP .NET App

    Thanks to all for the help with this one. As it turns out, the connection was static. I modified my code to use local connections that do not reside in a module and the problems seem to have gone away. I don't know what exactly is going on under the hood, but I do agree with tomkmvp that the data from a previous user was somehow being preserved.

    Again thanks for the help. I appreciate it!!

  • 07-14-2009, 2:25 PM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Central NJ
    • Posts 6,238
    • IIS MVPs

    Re: Errors In ASP .NET App

Page 1 of 1 (10 items)
Microsoft Communities