Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
HttpContext.Current.Session["conString"] = "connectionstring";

I am getting error :
Object reference not set to an instance of an object.
Posted
Comments
Tejas Vaishnav 22-Sep-14 5:11am    
Session is a part of Web-form, not part of Win-form. Because session are either stored in inproc (IIS process) or State Server or SQL Server or in some cases the mode of session is custom.

You can't maintain session in windows form application. Instead of session you can use global static variable here.
 
Share this answer
 
Just Create a class

C#
static class Global
{
    private static string _globalVar = "";

    public static string GlobalVar
    {
        get { return _globalVar; }
        set { _globalVar = value; }
    }
}


And use it as
C#
GlobalClass.GlobalVar = "any string value"


Read more http://stackoverflow.com/questions/1293926/c-sharp-winforms-global-variables[^]
 
Share this answer
 
There is no Session variables in windows forms.You can try this concept
Create a Static class that holds the User name and password and any other variables need in entire application.

Eg:

C#
public static class LogginInformations
{
    public static string UserID;
}


Now you can access the UserID from anywhere in your code, or set a value from any where.
For more information look on here.

http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900