本文介绍了访问本地数据库异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个关键项的应用程序.在应用启动时,所有枢轴都是从本地数据库文件加载的.在应用启动时,如果数据库文件不存在,我将创建它.

间歇地,我们收到以下异常.我无法解决此异常

System.Data.SqlServerCe.SqlCeException:找不到数据库文件.检查数据库的路径. [数据源= C:\ Data \ Users \ DefApps \ AppData \ {B72664A2-72C3-4010-9653-041DA78A9D27} \ Local \ DataFile.sdf ]  在System.Data.SqlServerCe.SqlCeConnection.Open(布尔无声)处在System.Data.SqlServerCe.SqlCeConnection.Open()处在System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser用户)处在 System.Data.Linq.SqlClient.SqlProvider.Execute(表达式查询,QueryInfo queryInfo,IObjectReaderFactory工厂,Object [] parentArgs,Object [] userArgs,ICompiledSubQuery []子查询,Object lastResult,Boolean isCompiledQuery)在System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression 查询,QueryInfo [] queryInfos,IObjectReaderFactory工厂,Object [] userArguments,ICompiledSubQuery []子查询,布尔值isCompiledQuery)在System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)   在System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute处执行[S](表达式)在System.Linq.Queryable.Count [TSource](IQueryable`1源)上

System.Data.SqlServerCe.SqlCeException: The database file cannot be found. Check the path to the database. [ Data Source = C:\Data\Users\DefApps\AppData\{B72664A2-72C3-4010-9653-041DA78A9D27}\Local\DataFile.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.Count[TSource](IQueryable`1 source)

推荐答案

我可以知道您在哪里创建数据库吗?我建议使用App.xaml.cs文件的构造函数.

May I know where you are creating database? I suggest to use App.xaml.cs file's constructor.

 public App()
        {

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

//Database creation
            LocalDBAccess.Initialize();

        }


如果您仍然遇到相同的问题,请告诉我.


Please let me know if you still get the same problem.


这篇关于访问本地数据库异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:34