在Windows手机上访问数据库时出错

时间:2013-12-04 18:06:39

标签: c# database windows-phone

当我点击我的应用程序上的某个按钮时...它会显示此代码的错误: member =(来自emp的上下文。成员选择emp).ToList();

请帮我解决一下

  

发生了'System.Data.SqlServerCe.SqlCeException'类型的异常   在Microsoft.Phone.Data.Internal.ni.dll中但未在用户中处理   代码

{System.Data.SqlServerCe.SqlCeException: The database file cannot be found. Check the path to the database. [ Data Source = C:\Data\Users\DefApps\AppData\{B4AFF75E-E308-4B3B-B77C-7E66E36E2513}\Local\Name.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.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Member.DBHelper.GetMember()
   at Member.Show.Viewmember_Loaded()
   at Member.Show..ctor()}

1 个答案:

答案 0 :(得分:0)

检查你的app.xaml.vb中是否有这个:

Private Sub CreateDatabase()
    Using c As DataContext = New DataContext(DataContext.ConnectionString)
        c.CreateIfNotExists()
        c.LogDebug = True
    End Using
End Sub

然后从你的App.xaml.vb中调用它:

Public Sub New()
    '...other initialisation codes
    Call CreateDatabase()
End Sub

如果你想要c#

,你可以转换