InProc vs StateServer

Discussion in 'ASP .Net' started by tshad, Jul 16, 2005.

  1. tshad

    tshad Guest

    I switched my site from InProc to StateServer a while ago which solve a
    problem I was having dropping my session cookies when the worker process

    This has been working well until today.

    I was looking at some sample code and found that it won't work under
    StateServer, but will under InProc.

    The message I get is:

    Unable to serialize the session state. Please note that non-serializable
    objects or MarshalByRef objects are not permitted when session state mode is
    'StateServer' or 'SQLServer'.

    What are the objects I can't use and why not?

    The code I was looking at was :
    <%@ Page Language="VB" Debug="False" Explicit="True" Buffer="True"%>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <html><head><title>Drilldown Datagrid Searching Within
    <script runat="server" language="VB">
    Sub Page_Load(Source As Object, E As EventArgs)
    Response.BufferOutput = "True"
    If Len(Request("search")) > 0 Or Len(Request("sub")) > 0 Then
    If Len(Request("search")) > 0 Then Session.Clear()
    MyDataGrid.CurrentPageIndex = 0 ' resets the Datagrid to page 1
    subsrch.visible = "true"
    subsrch.visible = "false"
    End If
    End Sub

    Sub BindGrid()
    Dim Source As DataView

    If Len(Request("search")) = 0 Then Source = CType(Session("CachedGrid"),
    If IsNothing(Source) Then
    Dim MyConnection As SqlConnection
    Dim MyCommand As SqlDataAdapter
    Dim RcdCount As integer
    Dim DS As DataSet

    Dim sqlQuery As String = "SELECT emp_id, fname, lname FROM employee where
    (fname like '%" & Request("search") & "%' or lname like '%" &
    Request("search") & "%') Order by emp_id asc"

    Dim strConn As String = "server=(local);uid=sa;pwd=;database=pubs;"
    MyConnection = New SqlConnection(strConn)
    MyCommand = New SqlDataAdapter(sqlQuery, MyConnection)
    DS = new DataSet()
    MyCommand.Fill(DS, "MyDataGrid")
    MyDataGrid.CurrentPageIndex = 0
    Source = DS.Tables(0).DefaultView
    ' Insert Dataset into Session
    Session("CachedGrid") = Source
    End If
    If Len(Request.Form("sub")) > 0 Then
    Session ("Sub") &= " and (fname LIKE '%" & Request.Form("sub") & "%' or
    lname LIKE '%" & Request.Form("sub") & "%') "
    Source.RowFilter = Session ("Sub").SubString(5)
    End If
    If (Source.Count.ToString) >= 1 Then
    MyDataGrid.visible = "true"
    msg.text = "<br><b>No records found</b>"
    subsrch.visible = "false"
    MyDataGrid.visible = "false"
    End If
    'Get count from Dataview row count, same as Datagrid row
    count.text = "<b>" & Source.Count.ToString & "
    </b>results found<br>"
    MyDataGrid.DataSource = Source
    Catch e As Exception
    MyDataGrid.CurrentPageIndex = 0 'reset the Datagrid back
    to page 1 on any errors
    End Try
    End Sub

    Sub MyDataGrid_Page(sender As Object, e As
    MyDataGrid.CurrentPageIndex = e.NewPageIndex
    End Sub
    <body bgcolor="#FFFFFF" topmargin="0" marginheight="0"
    <h3>Datagrid Drilldown Search Example</h3>
    <form method="post">
    <input type="text" name="search">
    <input type="submit" Value="Go">
    <form runat="server">
    <span id="subsrch" runat="server">
    Search Within results
    <input type="text" name="sub">
    <input type="submit" Value="Go">
    <br><asp:label id="msg" runat="server" />
    <br><asp:label id="count" runat="server" />
    <ASP:DataGrid id="MyDataGrid" runat="server"
    AllowPaging="True" PageSize="10" PagerStyle-Mode="NumericPages"
    PagerStyle-NextPageText="Next" PagerStyle-PrevPageText="Prev"
    BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3"
    CellSpacing="0" Font-Name="Verdana"
    Font-Size="8pt" HeaderStyle-BackColor="#FF8040"
    AlternatingItemStyle-BackColor="#eeeeee" />

    There are some objects as well as some "input" html. These normally

    What is the serialization that they are talking about that I can't use?


    tshad, Jul 16, 2005
    1. Advertisements

  2. tshad

    WJ Guest

    To store session state to stateServer and or Sql Server (ASPState), your
    class must be marked as [Serializable]. Otherwise, only InProc can handle
    stuffs like dataGrid. See example below:

    namespace nSession
    public class cSession
    public string YourName;
    public DateTime YourDOB;

    public cSession()
    There is a good article about SS, click here:

    WJ, Jul 16, 2005
    1. Advertisements

  3. tshad

    Robert Smith Guest

    The message I get is:

    Unable to serialize the session state. Please note that non-serializable
    objects or MarshalByRef objects are not permitted when session state mode is
    'StateServer' or 'SQLServer'.

    Robert Smith, Jul 16, 2005
  4. tshad

    tshad Guest

    But this isn't a class.

    It is just a straight ASP.NET page. I don't add anything that says it is
    Serializable, so what is causing this page not to work?

    tshad, Jul 16, 2005
  5. tshad

    tshad Guest

    That was the message I got.

    I just don't know why this page gives me the message, when all the other
    pages (about 150) don't.

    tshad, Jul 16, 2005
  6. tshad

    WJ Guest

    Trap these statements below to see if its bombed out:

    Dim Source As DataView
    If Len(Request("search")) = 0 Then Source =

    If the error happens here then DataView is not serializable ! Keep in mind
    that "Inproc" will work with DataSet, Table, View ,Grid...

    WJ, Jul 17, 2005
  7. tshad

    WJ Guest

    Correction: I was too fast. It should be:

    ' Insert Dataset into Session
    Session("CachedGrid") = Source
    End If

    The above Session "write" statement may have caused the error because the
    Source is DataView, which may not work with State and SQL Servers. But I
    could be wrong. IOW, you must find out where the exception takes place.



    WJ, Jul 17, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.