locked
Saving Session in database. RRS feed

  • Question

  • User1782571270 posted

    I have bunch of session for eg.

    Session["a"], Session["b"], Session["c"]

    Is there any way or is it possible to save all this session as one object or one session into database. 

    Thank you so much for help.

    Friday, November 23, 2012 2:51 PM

Answers

  • User-236004499 posted

    Hi,

    Read this carefully as this describes process.

    You need to have a table called "Tbl_SurveyMonitor".

    Tbl_SurveyMonitor table would be shown as below (Add any other necessary coloumns if require)

    ID,  CustID, StepID, SurveyComplete (True[1]/False[0])

    I assume you stores Customer details when customer representative start talking on phone with customer, I assume you use stored procedure(SP) to insert customer details. Use @@IDENTITY to get new cutomer ID and store in this table.

    (1) When first time customer representative contact to customer, your program needs to create an entry for the new customer in Tbl_SurveyMonitor table. Fill with data into the "CustID", "StepID" (First step ID), IsStepComplete = 0, SurveyComplete=0.
    (Note: enhance your existing SP to add new insert statement as explain above to record into the new table)

    (2) On every steps just update this customers StepID (create new SP called "usp_UpdateCustomerStep", on click on next update StepID with next stepID)

    (3) On completion of survey update StepID and CompletionID = 1 (Create new SP called "usp_CompleteCustomerStep"

    In Case of call dropped before completion, you now records in your DB on which step customer has dropped call (Note: If customer has dropped at end of a step then make sure Customer Representative click "next" to record next StepID).

    In your program, at first you need to check whether this customer exists or not (To check this you need to write stored procedure), if exists then look into the Tbl_SurveyMonitor table, get the stepID where SurveyComplete =0. So now you have StepID and CustomerID, now populate your respective page/view or wizard (if you have use wizard then).

    Note:
    To check customer exists or not (I assume you are doing right now using SP) if have SP then enhance that SP and check current customer's survey has been completed or not. if not then return CustID and Step ID so in your program you can jump on respective view otherwise start new survey (as usual).

    I hope this make sense to you.

    Regards,

    Pratik

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2012 6:08 PM

All replies

  • Friday, November 23, 2012 3:01 PM
  • User482643855 posted

    http://support.microsoft.com/kb/317604?wa=wsignin1.0

    https://support.discountasp.net/KB/a334/how-to-enable-aspnet-sql-server-session-on-your-web.aspx

    Saturday, November 24, 2012 11:04 PM
  • User131525570 posted

    Hi

    To store session objects in sql server database

    change the following settings in web.config, specify the connection string :

    <sessionState
    mode="SQLServer"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;user id=username;password=password"
    cookieless="false"
    timeout="20" />

    Also refer this article:

    http://www.developer.com/db/article.php/3595766/Storing-Session-State-in-a-SQL-Server-Database.htm

    Regards,

    Charan

    Monday, November 26, 2012 3:40 AM
  • User-236004499 posted

    Hi Ashesh,

    Can you explain bit more. It is not good idea to store lot of things into any type of session. If you can explain bit more than there may be better work around which would be efficient and scalable.

    Regards,

    Pratik

    Monday, November 26, 2012 3:30 PM
  • User1782571270 posted

    This is what am i trying to do. I am creating a web applications for Customer service. when customer drop their calls we are saving all the session in tables as one so incase if they comeback later we will search from their name and if we find their name then we will restore their old session. If you or anybody has any good way to do this let me know. So far i was able to store one session like this.

     using (MemoryStream ms = new MemoryStream())
                    {
                        object a = Session["name"];
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(ms, a);
                        
                        ms.Position = 0;
                        bSession = ms.ToArray();
                    }

    Monday, November 26, 2012 4:54 PM
  • User1779161005 posted

    Personally, I'd decouple yourself from Session and model the call as its own object. Then you have a self-contained model for the call and then persisting it is then easy (and you won't have to dig into each and every session value to save to remeber the state of the call). This seems like a cleaner approach to modeling the call.

    Then for acquiring the instance for the current call, perhaps you could use session or you could do a DB query, depengin upon the context. This is your call, but I'd warn against session in general.

    Tuesday, November 27, 2012 9:55 AM
  • User-236004499 posted

    Hi,

    After your little explaination. I assume  when customer representative on call he will use your application and go through from  various steps (record input into DB) and once call dropped before completion of all steps, later after 2 or 10 days when same customer come accorss and you want to start with where customer left. If this is the scenario in your application then what you are doing is absolutely incorrect. You have to rethink your process and re-design your architecture.

    If you think the business process I described as above is correct then let me know if you want then I can give you suggestion how you can accomplish your requirement.

    Regards,

    Pratik

    Wednesday, November 28, 2012 6:46 PM
  • User1782571270 posted

    Yes praticksolanki, 

    You are correct. Please advise me. 

    THank you.

    Thursday, November 29, 2012 12:18 AM
  • User-236004499 posted

    Hi,

    Read this carefully as this describes process.

    You need to have a table called "Tbl_SurveyMonitor".

    Tbl_SurveyMonitor table would be shown as below (Add any other necessary coloumns if require)

    ID,  CustID, StepID, SurveyComplete (True[1]/False[0])

    I assume you stores Customer details when customer representative start talking on phone with customer, I assume you use stored procedure(SP) to insert customer details. Use @@IDENTITY to get new cutomer ID and store in this table.

    (1) When first time customer representative contact to customer, your program needs to create an entry for the new customer in Tbl_SurveyMonitor table. Fill with data into the "CustID", "StepID" (First step ID), IsStepComplete = 0, SurveyComplete=0.
    (Note: enhance your existing SP to add new insert statement as explain above to record into the new table)

    (2) On every steps just update this customers StepID (create new SP called "usp_UpdateCustomerStep", on click on next update StepID with next stepID)

    (3) On completion of survey update StepID and CompletionID = 1 (Create new SP called "usp_CompleteCustomerStep"

    In Case of call dropped before completion, you now records in your DB on which step customer has dropped call (Note: If customer has dropped at end of a step then make sure Customer Representative click "next" to record next StepID).

    In your program, at first you need to check whether this customer exists or not (To check this you need to write stored procedure), if exists then look into the Tbl_SurveyMonitor table, get the stepID where SurveyComplete =0. So now you have StepID and CustomerID, now populate your respective page/view or wizard (if you have use wizard then).

    Note:
    To check customer exists or not (I assume you are doing right now using SP) if have SP then enhance that SP and check current customer's survey has been completed or not. if not then return CustID and Step ID so in your program you can jump on respective view otherwise start new survey (as usual).

    I hope this make sense to you.

    Regards,

    Pratik

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 29, 2012 6:08 PM