Error with using session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tinus
    New Member
    • Jul 2010
    • 30

    Error with using session

    Hi

    I am getting thid error
    Code:
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    Source Error:
    
    Line 18: 
    Line 19: <% 
    Line 20:     string thedate = Session["indate"].ToString();////;;;;????
    Line 21:     Response.Write("Starting SAS");
    Line 22:     try
    
    
    Source File: c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\WebSite1\SASrun.aspx
    upload.aspx
    Code:
    <%@ Page language="c#"Debug =true Codebehind="upload.aspx.cs" AutoEventWireup="false" 
    Inherits="Stardeveloper.UploadAccess.UploadForm" %>
    
     
    
    <script  runat="server">
    
    void Button2_Click(object sender, EventArgs e)    
    {
     Session["indate"] = Request["txtDate"];
     Response.Redirect("SASrun.aspx");
     }
        
    </script>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    
    <html>
    <head>
    </head>
    <body>
    <body style="background:#80B584">
    <form runat=server>
    <a href="default.aspx"><b>Main Page</b></a> &middot; Upload Files 
    		&nbsp; 
    <div id="message" runat="server" />
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <p style="font-family:arial;color:White;font-size:20px;">Upload new files.</p>
    <tr><td><b>MTMDetailed:</b></td><td><input type="file" class="stdInput" name="uploaded_file1"></td></tr>
    <tr><td><b>File TRI_FP:</b></td><td><input type="file" class="stdInput" name="uploaded_file2"></td></tr>
    <tr><td><b>indate     :</b></td><td><input type="text"id="txtDate" name="inputdate"/></td></tr>
    <tr><td align="right"><input type="submit" value="Submit"></td></tr>
    <asp:Button id="Button2" runat="server" Text="Submit" onClick="Button2_Click" />
    </table>	
    </form>
    
    </body>
    </html>
    This is part of the code where error is coming from.

    Code:
    %@ Page Language="C#" Debug="true" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Web.Mail" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Configuration" %>
    <%@ Import Namespace="System.Xml.Linq" %>
    <%@ Import Namespace="System.Data.SqlClient"%> 
    <%@ Import Namespace="System.Data.OleDb"%> 
    
    
    ////////SAS///////////////////
    <html>
    <head>
    <title>Session Page 2</title>
    </head>
    <body><p>ASP.NET C# session page 2</p>
    <p>theDate: <%=Session["indate"]%></p>
    
    <% 
        string thedate = Session["indate"].ToString();////;;;;????
        Response.Write("Starting SAS");
        try
        {
            // create the ProcessStartInfo using "cmd" as the program to be run,
            // and "/c " as the parameters.
            // Incidentally, /c tells cmd that we want it to execute the command that follows,
            // and then exit.
    //        string thedate = Session["indate"];
            //string thedate = Convert.ToString(Session["indate"]);
       
       string exec_str = "sas.exe -sysparm " +thedate;
            exec_str = exec_str + " -sysin C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Code/a00_run_file.sas";
            System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo("cmd", "/c " + exec_str);
    Please advise.
    Last edited by jhardman; Dec 18 '10, 12:42 AM. Reason: Accidentally posted in classic asp forum. Moved to asp.net
  • sanamkm
    New Member
    • Dec 2010
    • 5

    #2
    Hi,

    >>In global.asax there is sectio for session start

    void Session_Start(o bject sender, EventArgs e)
    {
    }

    here you can assign your session a value(can b null(" "),"1","0", etc)

    Eg:Session["indate"]=" ";


    >>And in code where the error occur place like this

    if(Session["indate"].ToString()!="" )
    {
    string thedate = Session["indate"].ToString();////;;;;????
    Response.Write( "Starting SAS");
    continue coding...
    }

    Hope this will work for your code


    Have a nice day

    Comment

    Working...