[CLOSED] Session NullException

  1. #1

    [CLOSED] Session NullException

    Hi!

    Well. I see it as no your problem, but I would be grateful for any help or hint.

    Because a decision out of my scope, our application (run in our own servers) will connect in databases (SQL Server 2000) located in customer webserver. Becaise of this, I need save the connectionString in Session (or HttpContext.Current.Session).

    It happens that, when loading or refreshing the grids (gridPanels), when I try to get the connectionstring of the session, it returns me a NullException.
    I read somewhere that this is possibly because of asynchronous call.

    Have you ever had this problem? is there any workaround?

    If there is another hint where I can store my connectionstring for each user and retrieve it at the time to load (and reload) the grids, I would be very grateful.

    Thanks for any help.
    Last edited by Daniil; Feb 02, 2012 at 4:32 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I think you should just keep Session alive.

    If you would google with "session keep alive" you will get many info about it.

    Within Ext.NET you could use a TaskManager to "kick" a server:
    https://examples2.ext.net/#/TaskManager/Basic/Overview/

    Every 100 seconds should be enough.
  3. #3
    Hi Daniil.. thanks for your answer!

    Well... I´m not sure that the problem is a session time-out. I set in my webconfig the session time-out to 20 minutes, and the problem occurss few seconds after the application starts.

    it seems to me, the problem occurs after an asynchronous request to load or reload of the gridPanel. My source data is a SQL Server 2008, and my Store Proxy is a WebMethod of my WebService.

    I created a test project that exemplifies this bug:
    A gridPanel bind to a WebService.
    The WebService has two methods. One return a ext.net.Paging and other return a session value.
    In default.aspx Page_Load, I set in Session a value.
    In default.aspx, there are a button. If you click in this button, trigger a function that consumes the WebService1.GetSessionValue. Its work.
    The gridPanel is load with values returned by Webservice1... its work to.
    If you mark the checkbox to 'Show Session Value in Webservice1.getData when refresh gridPanel', and click in 'refresh' button of bottonbar of gridPanel, in the getData, a code that try get Session value and Show in a Message box is enable. But this code triggers a Null Exception erro when try get Session value.

    I know this is not your responsibility, but if you can take a look and tell me if you have any idea, I'll be very grateful...

    Follow the Test Project code:

    class Customer
    Public Class Customer
        Private mvarCode As Long
        Private mvarName As String
        Private mvarBirthDate As Date
    
        Public Sub New()
            MyBase.New()
            mvarCode = 0
            mvarName = ""
            mvarBirthDate = #1/1/0900#
        End Sub
    
        Public Sub New(pCode As Long, pName As String, pBirthDate As Date)
            mvarCode = pCode
            mvarName = pName
            mvarBirthDate = pBirthDate
        End Sub
    
        Public Property Code As Long
            Get
                Return mvarCode
            End Get
            Set(value As Long)
                mvarCode = value
            End Set
        End Property
    
        Public Property Name As String
            Get
                Return mvarName
            End Get
            Set(value As String)
                mvarName = value
            End Set
        End Property
    
        Public Property BirthDate As Date
            Get
                Return mvarBirthDate
            End Get
            Set(value As Date)
                mvarBirthDate = value
            End Set
        End Property
    
    End Class
    WebService1
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    <System.Web.Script.Services.ScriptService()>
    Public Class WebService1
        Inherits System.Web.Services.WebService
    
        <WebMethod()> _
        <ScriptMethod()> _
        Public Function GetData(start As Long, limit As Long, sort As String, filter As String) As Paging(Of Customer)
            Dim vList As List(Of Customer) = New List(Of Customer)
    
            If filter = "True" Then
                MsgBox(HttpContext.Current.Session("MySessionValue"))
            End If
    
            vList.Add(New Customer(1, "José Roberto", #1/2/1978#))
            vList.Add(New Customer(2, "Fabio Zatta", #4/24/1976#))
            vList.Add(New Customer(3, "Kelly Esperança", #5/21/1982#))
            vList.Add(New Customer(4, "Veríssimo Rizzi", #6/19/1981#))
    
            Return New Ext.Net.Paging(Of Customer)(vList, vList.Count)
    
        End Function
    
        <WebMethod()> _
        <ScriptMethod()> _
        Public Function GetSessionValue() As String
            Return HttpContext.Current.Session("MySessionValue")
        End Function
    
    End Class
    Default.aspx
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Session.Add("MySessionValue", "This is my Session Value!")
        End Sub
        
        Protected Sub ShowSession(sender As Object, e As DirectEventArgs)
            Dim vmsg As Ext.Net.MessageBox = New Ext.Net.MessageBox
            Dim ws As WebApplication1.WebService1 = New WebApplication1.WebService1
            vmsg.Alert("Session Value", ws.GetSessionValue)
            vmsg.Show()
        End Sub
        
    </script>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Session NullException</title>
    
        <script type="text/javascript">
         
             function getFilter() {
                var sFilter = "0";
    
                sFilter = Session.Test.chkReadSessionValue.getValue();
            
                return sFilter;
            }    
    
        </script>
    
    </head>
    <body>
        <ext:ResourceManager ID="resManager1" runat="server" Locale="pt-BR" Namespace="Session.Test"/>
        <ext:Panel runat="server" X="5" Y="5" Layout="AbsoluteLayout" Height="400" Width="600">
            <Items>
                <ext:Button runat="server" id="btnShowSessionValue" text="Show Session Value" x="50" y="5" width="300" heigth="50">
                    <DirectEvents>
                        <Click OnEvent="ShowSession" />
                    </DirectEvents>
                </ext:Button>
                <ext:Checkbox runat="server" ID="chkReadSessionValue" x="50" Y="30"/>
                <ext:DisplayField ID="DisplayField1" runat="server" Text="Show Session Value in Webservice1.getData when refresh gridPanel" x="80" Y="30" Width="400"/>
                <ext:GridPanel runat="server" ID="grid1" Title="Customers" Frame="true" Layout="FitLayout" IconCls="icon-sugestoes" ButtonAlign="Right" x="50" Y="50" Width="500" Height="300">
                    <Store>
                        <ext:Store ID="Store1" runat="server" RemoteSort="true" PageSize="10">
                            <Proxy>
                                <ext:AjaxProxy Json="true" Url="~/WebService1.asmx/GetData">
                                    <ActionMethods Read="POST" />
                                    <Reader>
                                        <ext:JsonReader Root="d.Data" TotalProperty="d.TotalRecords" />
                                    </Reader>
                                </ext:AjaxProxy>
                            </Proxy>
                            <AutoLoadParams>
                                <ext:Parameter Name="start" Value="0" Mode="Raw" />
                                <ext:Parameter Name="limit" Value="10" Mode="Raw" />
                            </AutoLoadParams>
                            <Parameters>
                                <ext:StoreParameter Name="filter"  Value="getFilter()" Mode="Raw" />
                            </Parameters>
                            <Model>
                                <ext:Model runat="server" IDProperty="Code" ID="ctl10">
                                    <Fields>
                                        <ext:ModelField  Name="Code" />
                                        <ext:ModelField  Name="Name" />
                                    </Fields>
                                </ext:Model>
                            </Model>
                            <Sorters>
                                <ext:DataSorter Property="Code" Direction="DESC" />
                            </Sorters>
                        </ext:Store>
                    </Store>
                    <ColumnModel runat="server" ID="columnmodel1">
                        <Columns>
                            <ext:Column runat="server" Text="ID" DataIndex="Code" Width="75px" Sortable="true" />
                            <ext:Column runat="server" ID="Name" Text="Name" DataIndex="Name" Width="400px" Sortable="true" />
                        </Columns>
                    </ColumnModel>
                    <BottomBar>
                        <ext:PagingToolbar ID="tbPagingSugestoes" runat="server" DisplayInfo="true"
                            DisplayMsg="List {0} - {1} of {2}" EmptyMsg="No records">
                            <Items>
                                <ext:Label ID="Label1" runat="server" Text="Page Size:" />
                                <ext:ToolbarSpacer runat="server" Width="10" />
                                <ext:ComboBox ID="cmbPageSize" runat="server" Width="80">
                                    <Items>
                                        <ext:ListItem Text="5" />
                                        <ext:ListItem Text="10" />
                                        <ext:ListItem Text="15" />
                                        <ext:ListItem Text="20" />
                                        <ext:ListItem Text="25" />
                                        <ext:ListItem Text="30" />
                                    </Items>
                                    <SelectedItems>
                                        <ext:ListItem Value="10" />
                                    </SelectedItems>
                                    <Listeners>
                                        <Select Handler="#{grid1}.store.pageSize = parseInt(this.getValue(), 10); #{grid1}.store.load({params:{start:0}});" />
                                    </Listeners>
                                </ext:ComboBox>
                            </Items>
                        </ext:PagingToolbar>
                    </BottomBar>
                </ext:GridPanel>
                
            </Items>
        </ext:Panel>
    </body>
    </html>
  4. #4
    By default, Session is disabled for WebService.

    It works during DirectEvent, because, we think, a WebMethod is called from the page context.

    Please set up the following attribute for WebMethod.
    [WebMethod(EnableSession = true)]
  5. #5
    Here is the good article about using Session in WebService.
    http://www.codeproject.com/Articles/...-a-Web-Service
  6. #6
    Daniil, you're the guy!!!

    I am very grateful for your help!
    Thanks a lot!

Similar Threads

  1. [CLOSED] MVC + Session timeout
    By borja_cic in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 15, 2011, 5:59 PM
  2. [CLOSED] How can I know session timeout?
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 08, 2011, 8:37 AM
  3. [CLOSED] keep session alive
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 23, 2011, 4:39 PM
  4. [CLOSED] Session variables
    By webppl in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 24, 2011, 11:06 PM
  5. [CLOSED] ASP.NET Session and Coolite
    By shahidmughal in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 08, 2009, 12:48 AM

Tags for this Thread

Posting Permissions