locked
SQL Server Compact and Session State RRS feed

  • Question

  • User895124780 posted

    Is it possible to store session state in SQL Server CE? I was finding any posts about it and didn't get any examples. I develop an asp.net mvc 4 application.  

    Friday, November 16, 2012 2:18 AM

All replies

  • Saturday, November 17, 2012 7:29 AM
  • User895124780 posted
    Standart implementation means that you will use Sql Server as a service. Look at typcal web.config lines:

    <sessionState mode="SQLServer" sqlConnectionString="???" customProvider="DefaultConnection">
       <providers>
         <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0,                                                             Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="WeddingStoreDbConnectionString" />
       </providers>
    </sessionState>

    But I want to use SQL Server CE edition, and that means only using local files, there is no url for Sql Server instance. I decided to implement my own SessionStateProvider which should work with SQL Server CE. I have implemented membership and roles providers and they worked fine. One more remains

    Sunday, November 18, 2012 11:39 AM
  • User-489377026 posted

    Hi karyazhkin,

    <sessionState mode="SQLServer" sqlConnectionString="???" customProvider="DefaultConnection">

    Your sqlConnectionString should be  "Data Source=|DataDirectory|\Database.sdf"

    refer:

    http://msdn.microsoft.com/en-us/library/ms174053.aspx

    Best Regards   

    Tuesday, November 20, 2012 3:05 AM
  • User895124780 posted

    Yep, I've tried to go by this method, but it doesn't work for me. The error:

    "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

    I used Universal Provides for Sql Server CE, and everything works fine except for the session storing in SqlServer mode. So I decided to implement my own session-state store provider which would work with Sql Ce throughout the Entity Framework. it works perfectly

    Link to msdn about the realization of the provider: http://msdn.microsoft.com/en-us/library/ms178587(v=vs.100).aspx

    Tuesday, November 20, 2012 5:31 AM
  • User482643855 posted

    Sql Server Compact has its own limitations i do not think it is advisable to sotre session state in sql server ce.

    Wednesday, November 21, 2012 6:21 AM