SQL CE File sharing violation : Error, Solution required RRS feed

  • Question

  • User-1327394822 posted

    I am logging all exceptions in my _PageStart.cshtml file and the below error keeps occurring on and off.

    The following error occurred
    There is a file sharing violation. A different process might be using the file. [ D:\home\site\wwwroot\App_Data\MyDatabase.sdf ]
       at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
       at System.Data.SqlServerCe.SqlCeConnection.Open()
       at WebMatrix.Data.Database.EnsureConnectionOpen()
       at WebMatrix.Data.Database.<QueryInternal>d__0.MoveNext()
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       at WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args)
       at ASP._Page_Collection_cshtml.Execute() in d:\home\site\wwwroot\Collection.cshtml:line 32
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
       at System.Web.WebPages.WebPage.ExecutePageHierarchy()
       at System.Web.WebPages.StartPage.RunPage()
       at ASP._Page__PageStart_cshtml.Execute() in d:\home\site\wwwroot\_PageStart.cshtml:line 5

    Monday, October 3, 2016 4:16 PM

All replies

  • User1853794821 posted

    Take a look at https://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=9716~-1

    Monday, October 3, 2016 5:48 PM
  • User-2057865890 posted

    Hi Gautam,

    Please make sure that the First connection to the database is not opened in an Exclusive mode. 

    Multi-connection acces details can be found at http://msdn.microsoft.com/en-us/library/ms171750.aspx.

    Best Regards,


    Tuesday, October 4, 2016 7:55 AM
  • User379720387 posted

    Here are the two connection strings for one of my projects:

    <add name="StarterSite" connectionString="Data Source=|DataDirectory|\StarterSite.sdf" providerName="System.Data.SqlServerCe.4.0" />
    <add name="Entities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlServerCe.4.0;provider connection string='Data Source=|DataDirectory|\StarterSite.sdf'" providerName="System.Data.EntityClient" />

    The MSDN article indicates I can use: 

    "Mode = Shared Read"

    Where would it go in my connection strings?

    Tuesday, October 4, 2016 11:01 AM