Access to the database file is not allowed. [ File name = UserRecord.sdf ]

Unanswered Access to the database file is not allowed. [ File name = UserRecord.sdf ]

  • Sunday, March 04, 2012 4:36 PM
     
      Has Code

    when i call create database i got this error,
    it's wcf service application and i've created a database programmatically
    I dont know what path will use?? please any idea


    Server Error in '/' Application.

    Access to the database file is not allowed. [ File name = UserRecord.sdf ]

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlServerCe.SqlCeException: Access to the database file is not allowed. [ File name = UserRecord.sdf ]

    Source Error:

    Line 29:             {
    Line 30:                 if (URdb.DatabaseExists() == false)
    Line 31:                     URdb.CreateDatabase();
    Line 32:             }
    Line 33:         }

    Source File: C:\Users\ProjectServer\Desktop\Projects\Projects\editing\2\HospitalService\HospitalService\RecordOperations.cs    Line: 31

    Stack Trace:

    [SqlCeException: Access to the database file is not allowed. [ File name = UserRecord.sdf ]]
       System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.CreateDatabase() +427
       System.Data.Linq.DataContext.CreateDatabase() +24
       HospitalService.RecordOperations.CreateDatabase() in C:\Users\ProjectServer\Desktop\Projects\Projects\editing\2\HospitalService\HospitalService\RecordOperations.cs:31
       HospitalService.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\ProjectServer\Desktop\Projects\Projects\editing\2\HospitalService\HospitalService\WebForm1.aspx.cs:14
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
    • Moved by Bob BeaucheminMVP Sunday, March 04, 2012 5:03 PM Moved to a more appropriate forum for best response. (From:.NET Framework inside SQL Server)
    •  

All Replies

  • Sunday, March 04, 2012 6:30 PM
    Moderator
     
     
    Could you share your connetion string?

    Please mark as answer, if this was it. Visit my SQL Server Compact blog

  • Sunday, March 04, 2012 7:54 PM
     
     
    private const string strConnectionString = @"myDatabase.sdf";
            /// <summary>
            /// Create Database
            /// </summary>
            public static void CreateDatabase()
            {
                // added because of error, sql compact not intended in asp.net
                AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
                using (UserRecordDataContext URdb = new UserRecordDataContext(strConnectionString))
                {
                    if (URdb.DatabaseExists() == false)
                        URdb.CreateDatabase();
                }

            }
  • Friday, March 23, 2012 7:20 AM