Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 8 Windows phone 8已发布应用程序。找不到数据库文件。检查数据库的路径_Windows Phone 8_Sql Server Ce - Fatal编程技术网

Windows phone 8 Windows phone 8已发布应用程序。找不到数据库文件。检查数据库的路径

Windows phone 8 Windows phone 8已发布应用程序。找不到数据库文件。检查数据库的路径,windows-phone-8,sql-server-ce,Windows Phone 8,Sql Server Ce,以下是db初始化代码: using (MyDbContext db = new MyDbContext("Data Source=isostore:/my_db.sdf")) { if (!db.DatabaseExists()) { db.CreateDatabase(); } } 代码在调试版本上运行良好,但在发布到windows phone应用商店后失败 堆栈跟踪: The database file cannot be found. check the p

以下是db初始化代码:

using (MyDbContext db = new MyDbContext("Data Source=isostore:/my_db.sdf"))
{
   if (!db.DatabaseExists())
   {
      db.CreateDatabase();
   }
}
代码在调试版本上运行良好,但在发布到windows phone应用商店后失败

堆栈跟踪:

The database file cannot be found. check the path to the database. [ Data Source = C:\Data\Users\DefApps\AppData\{A1F26781-AA93-432A-AD80-B02825C3BBA8}\Local\my_db.sdf ]
   at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
   at System.Data.SqlServerCe.SqlCeConnection.Open()
   at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult, Boolean isCompiledQuery)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries, Boolean isCompiledQuery)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
   at MyApp.Models.SomeModel.restoreObjectData()

谢谢您的帮助。

您需要将数据库复制到isostore文件夹,如果您使用SQL CE工具箱DataConntext,则可以使用以下代码:

if (!db.DatabaseExists())
{
  db.CreateIfNotExists();
}

对不起,伙计们,我发现了一个问题。我在这里编写了数据库初始化代码

        public App()
        {
        // Show graphics profiling information while debugging.
        if (System.Diagnostics.Debugger.IsAttached)
        {
            db.create();
        }