.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

storing Session in sql server?

Posted By:      Posted Date: August 26, 2010    Points: 0   Category :ASP.Net


I want to show all the activities of the logged in user in a gridview. I am using VS 2010. please suggest some good ways of doing it.



View Complete Post

More Related Resource Links

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

SQL Server Session state problem.


Hi to all,

I have some things that I want to know. I am right now using a free asp.net webhosting ("somee.com"). The problem is that when I am visiting a page, there's a tendency that values stored in my session variables are lost. Therefore, it causes an error when the requested page is loaded.

1. I am thinking of using sessionState mode="SqlServer". Will it solve my problem?

Actualy Im working on it but Im having problems when connecting to the sql database.

2.  Is that a problem in the webhost?

3. Do free webhosting sites provide allow session state in the sql server?. Because ive tried it locally into my computer and error say's i should intall the ASP.NET Session State SQL Server version 2.0 or above.

Generating and storing html pages in User Directories on the server



I come from corporate asp.net development, and I am now working on a public website which will get a lot of traffic, perhaps a million users a day.  So I am faced with a ton of performance and scalability questions.

I would like to share some thoughts and see if my approaches resonate with any good practices, or perhaps I am heading down the wrong path...  Either way, I want to hear opinions.

(My number one concern is the fact that I am using asp.net for a public website.  I don't know of a lot of websites using asp.net)

I am using asp.net 2.0 (I know, its not the latest technology but I don't need any advanced features of asp.net 3.5 or 4, unless there are significant improvements geared towards what I am doing) 

On launch date, this will be running on a dedicated Windows Server 2008 running on Intel ATOM 330 1MB L2 Cache 1.6Ghz Dual-Core with 2GB DDR RAM.  Its fully managed by a full service hosting company which gives me an option to upgrade to a bigger server within a few hours.  I can even move the site to a webfarm if the traffic demands it.

So I have a User Dashboard, where users can create albums and upload pictures.  So what I am doing

Best way of storing Serialized objects into Sql server

For some reason, my app need to store serialized objects into SQL Server. Can you guys please tell me the pros and cons and what's the best way of doing it.

Storing large data in Session State

Hi, We have a scenario where we need to store large tables of data on Session in asp.net page. on a highlevel we have to store following data  1> A table (table 1) with 1000 rows and 8 to 10 columns. 2> A table(table 2) with 500 rows and 8 to 10 columns (actually user can add the data from table 1 to table 2, so as user keeps on adding from table 1 we remove the data and put it in table 2) 3> Another table(table 3) with 1000-1200 rows each having 3 columns. We are having a webfarm, so we need to store it in either SateServer of Oracle DB, please advise which one is better. What would be the performance implications of storing such huge data on the server. One more thing is at any point of time max of 70 -80 people will be accessing our website, so will this cause any performance degradation? Thanks in anticipation Harsha

Sharing the session variables between two .net applications using SQL Server Mode?

Hi, I have two different IIS applications within the same domain(let us say www.mydomain.com) , both of these applications use the same database instance(same connectionstring), now what I want is that both of applications can see each sessions variables , can SQL Server session state mode helps in this case? Did someone try that before? Is there any other way to share the session variables? Please help.  

Weird casting error (storing Generic list in Session)


Am trying to store a generic list in Session to act as a simple shopping cart. Am getting a weird casting error when I try and retrieve it from Session.

A critical error has occurred.
[A]System.Collections.Generic.List`1[MyCartItem] cannot be cast to [B]System.Collections.Generic.List`1[MyCartItem].
Type A originates from 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll'.
Type B originates from 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    in the context 'LoadNeither' at location 'C:\WINDOWS\assembly\GAC_32\mscorlib\\mscorlib.dll'.

I have a class variable defined:

List<MyCartItem> _cart;

In the Load event I have:

_cart = (Session["MyCart"] != null) ? (List<MyCartItem>)Session["MyCart"] : new List<MyCartItem>();

How do I posting session information to server through the hidden field ?


I have the following in my code (Login.aspx page)


 <script language="javascript" type="text/javascript">


WCF session client service reference "State" is not updated when the server side has closed


I am using vb.net (Visual Studio 2008 with framework 3.5). I have a server that exposes several services requiring sessions. I am using wsHttpBinding for all. One of my requirements is to allow non-dot net third parties to access these services. When a client connects to a service and then some time later the server goes away, the state of the connection is still reporting "open".

Currently I have implemented a "ping" function on the server. My client calls this function every 5 to 10 seconds and if the server does shutdown, I get alerted with an exception error. This works, but I was wondering if there is a way where I don't have to call my ping function?

I don't want to use a dual connection binding and I was hoping to use the connection state variable? But, I don't know how to get it to update by itself. The client user application could just wait until it goes to invoke a service method, but I was wondering if there was another way.

Thanks in advance!!


using Session state server



My ASP.NET web application is hosted in multiple servers  with a Network Load balancer Hardware. I am facing issues in session management during the site navigation. Frequently the session values are lost and application errors out with session not found. Currently the Site is configured with the Session mode as Inproc.

I would like to know:

1. Whether changing the Session mode to State server will solve the session management issue.
2. If changing the session mode then what would be the best configuration for the state server.
3. Is there any other configuration settings that needs to be done in the State server as well as in the application

Thank you

Session and session variables not stable in development server....


Hi I have a strange problem in a website that runs in a server to which I am connected through VPN...

I use some session variables to get the job done(shopping cart, etc) but it is not stable..manytimes I get no items in session object and other times(refreshing the page) I get missing data...I downloaded the entire site code to my local pc and debugged it and run it succesfully without any session data missing...When I run it in the server, I get bad session again: no products in shopping cart or products with missing quantities...

The same website runs smoothly in our production server too....The problem is with our development server...

Any help would be greatly appreciated..

Thanks in advance,


Retrieve data from SQL server based on login username (session data)



I'm trying to make a dropdown list with data available based on the users login name. Heres what I have as my SQL Query in the SQLDataSource:

SELECT Client_Name, Client_ID FROM Client WHERE (Client_Name LIKE '%@Client_Name%')

So say if the login username is "User1" but the database client name is "User1 Steel" I want the dropdownlist to pull "User1 Steel" as the display and Client_ID as the value from the dropdown list. 

I dont know how to use the session data!

Storing TcpClient object in session



I am experimenting with an asp.net application wherein I do the following things (simplified for the purpose of this discussion):

1. Take user's gmail username/password (don't fret, I am not doing any nasty stuff Wink).

2. Create TcpClient object and connect it to the Gmail's POP email server using the provided username/password.

3. I am going to use this TcpClient object to download mails for the user.

Following is the problem I face:

1. Say I have presented the user with the subject lines of all his emails.

2. Now he clicks one subject line to download the message. (This will create the post-back to the aspx page)

3. When I receive the post back, will I be able to re-use the same TcpClient object which I connected to the POP server, if I store that object as a Session variable?

I doubt the streams associated with the object will not remain valid.

Is this even the right method to achieve what I am trying to achieve?



state server for session.



  i studied like state server retrieve the session if the web server restarts.

here my doubt is application will not work while webserver restarts.then what is the use of retrieve the session after restrart the webserver?

Session variable, Gridview paging and Storing the ID HELP




I have a gridview and a checkbox. I am able to pass the checkbox id to a textbox in the same page. This is then passed as a session variable. However, when I place an option to page and select the checkbox items in the next page, the session variable resets.

Please see below code, how do I store "all checkbox" throughout all paging and store it in the session page?


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BorderStyle="Solid"    CellPadding="4" DataKeyNames="Categoryid" 
            BorderColor="Silver" BorderWidth="1px"    Width="300px" 
            DataSourceID="SqlDataSource1" AllowPaging=

Soundplayer.PlayLooping Not Working In Terminal Server Session


I have the need to play a wav file continously until a condition occurs.  Within our application I am creating an instance of system.media.soundplayer, setting the path a wav file, and calling PlayLooping.  I wrote and tested the code locally (VS 2010, 3.5 framework, C#) on my windows 7 machine and it worked fine but when I deployed it to a Windows Server 2003 machine and logged in via an RDP connection the sound only plays once and then stops. 

I did some searching and only found one instance where someone else had this issue.  Is this a known issue?

Storing session data continuouly




Is it possible to store gridview session data after each postback. I have a gridview and a checkbox within. Each time a user clicks the checkbox, I like to store the gridview ID in a session. After browsing through various pages, I like this session data to continuously store the information up to 20mins?


How can I continously store the session variable. Please can someone provide a sample? Say a text box and if I enter 1 click on a hyperlink (where session variable is stored) return back to the page, enter 2 click hyperlink then I should get in the session 12?

Any one know how to do this? Please provide code in VB.

THanks! Nijojo

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend