System.Data.Linq.dll 中发生了 'System.Data.SqlServerCe.SqlCeException' 类型的未处理异常
An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.Linq.dll
我收到以下错误,我不知道为什么,因为我的应用程序 运行 4 小时前是正常的,但现在不工作了,我没有做任何更改..
An unhandled exception of type
'System.Data.SqlServerCe.SqlCeException' occurred in
System.Data.Linq.dll
我在行 db.SubmitChanges();
中收到错误。我将完整代码留在下面。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
using Microsoft.Phone.Shell;
using System.ComponentModel;
using System.Data.Linq;
using System.Collections.ObjectModel;
namespace Aplicativo_Windows_Phone
{
public partial class AddColetor : PhoneApplicationPage
{
string email;
public AddColetor()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
NavigationContext.QueryString.TryGetValue("email", out email);
}
private void btnAdd_Click_1(object sender, RoutedEventArgs e)
{
AppDataContext db = new AppDataContext();
Coletor coletor = new Coletor();
if (rdNorte.IsChecked == true)
{
coletor.Latitude = Convert.ToInt32(txtLat.Text);
}
else
{
coletor.Latitude = Convert.ToInt32(txtLat.Text) - (2 * Convert.ToInt32(txtLat.Text));
}
if (rdLeste.IsChecked == true)
{
coletor.Longitude = Convert.ToInt32(txtLong.Text);
}
else
{
coletor.Longitude = Convert.ToInt32(txtLong.Text) - (2 * Convert.ToInt32(txtLong.Text));
}
if (txtLat.Text != "" && txtLong.Text != "" && rdNorte.IsChecked == true || rdSul.IsChecked == true && rdLeste.IsChecked == true || rdOeste.IsChecked == true)
{
foreach (var pessoa in db.Pessoas)
{
if (pessoa.Email == email)
{
pessoa.Coletores.Add(coletor);
}
}
db.Coletores.InsertOnSubmit(coletor);
db.SubmitChanges();
NavigationService.Navigate(new Uri("/ColetoresPage.xaml", UriKind.RelativeOrAbsolute));
}
else
{
MessageBox.Show("Preencha todos os campos e marque as opções para adicionar um coletor");
}
}
private void btnCancel_Click_1(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/ColetoresPage.xaml", UriKind.RelativeOrAbsolute));
}
}
}
Coletor class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;
namespace Aplicativo_Windows_Phone
{
#pragma warning disable 0169, 0649
[Table(Name = "Coletores")]
public class Coletor
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int Id { get; set; }
[Column]
public float Latitude { get; set; }
[Column]
public float Longitude { get; set; }
[Column(Name = "Pessoa")]
private int? pessoaId;
private EntityRef<Pessoa> _pessoa = new EntityRef<Pessoa>();
[Association(Name = "FK_Coletores_ColetorPessoa", IsForeignKey = true, Storage = "_pessoa", ThisKey = "pessoaId")]
public Pessoa Pessoa
{
get { return _pessoa.Entity; }
set { _pessoa.Entity = value; }
}
private EntitySet<Ocorrencia> _ocorrencias = new EntitySet<Ocorrencia>();
[Association(Name = "FK_Ocorrencias_ColetorOcorrencias", Storage = "_ocorrencias", ThisKey = "Id", OtherKey = "coletorId")]
public ICollection<Ocorrencia> Ocorrencias
{
get { return (from co in ColetorOcorrencias select co.Ocorrencia).ToList(); }
set { _ocorrencias.Assign(value); }
}
private EntitySet<PessoaColetor> _pessoaColetores = new EntitySet<PessoaColetor>();
[Association(Name = "FK_PessoaColetores_Coletores", Storage = "_pessoaColetores", OtherKey = "coletorId", ThisKey = "Id")]
private ICollection<PessoaColetor> PessoaColetores
{
get { return _pessoaColetores; }
set { _pessoaColetores.Assign(value); }
}
private EntitySet<ColetorOcorrencia> _coletorOcorrencias = new EntitySet<ColetorOcorrencia>();
[Association(Name = "FK_ColetorOcorrencias_Coletores", Storage = "_coletorOcorrencias", OtherKey = "coletorId", ThisKey = "Id")]
private ICollection<ColetorOcorrencia> ColetorOcorrencias
{
get { return _coletorOcorrencias; }
set { _coletorOcorrencias.Assign(value); }
}
public ICollection<Pessoa> Pessoas
{
get { return (from pc in PessoaColetores select pc.Pessoa).ToList(); }
}
}
}
根据过去的经验,这里要冒险。 SqlServerCE 驱动程序有两种版本,x86 和 x64。通常,机器上只能安装一个,安装程序将在第二个上失败。但是,如果先安装 x86 驱动程序,然后再安装 x64,则可以在命令行上使用 /force 开关。
这可能对您的问题有帮助,也可能没有帮助,从提供的详细信息很难判断。
好的,我不知道为什么,但现在我的应用程序可以运行了。我认为这个错误是 Visual Studio 的一种错误,所以,为了解决我的问题,我刚刚重新启动了我的电脑。
我收到以下错误,我不知道为什么,因为我的应用程序 运行 4 小时前是正常的,但现在不工作了,我没有做任何更改..
An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.Linq.dll
我在行 db.SubmitChanges();
中收到错误。我将完整代码留在下面。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
using Microsoft.Phone.Shell;
using System.ComponentModel;
using System.Data.Linq;
using System.Collections.ObjectModel;
namespace Aplicativo_Windows_Phone
{
public partial class AddColetor : PhoneApplicationPage
{
string email;
public AddColetor()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
NavigationContext.QueryString.TryGetValue("email", out email);
}
private void btnAdd_Click_1(object sender, RoutedEventArgs e)
{
AppDataContext db = new AppDataContext();
Coletor coletor = new Coletor();
if (rdNorte.IsChecked == true)
{
coletor.Latitude = Convert.ToInt32(txtLat.Text);
}
else
{
coletor.Latitude = Convert.ToInt32(txtLat.Text) - (2 * Convert.ToInt32(txtLat.Text));
}
if (rdLeste.IsChecked == true)
{
coletor.Longitude = Convert.ToInt32(txtLong.Text);
}
else
{
coletor.Longitude = Convert.ToInt32(txtLong.Text) - (2 * Convert.ToInt32(txtLong.Text));
}
if (txtLat.Text != "" && txtLong.Text != "" && rdNorte.IsChecked == true || rdSul.IsChecked == true && rdLeste.IsChecked == true || rdOeste.IsChecked == true)
{
foreach (var pessoa in db.Pessoas)
{
if (pessoa.Email == email)
{
pessoa.Coletores.Add(coletor);
}
}
db.Coletores.InsertOnSubmit(coletor);
db.SubmitChanges();
NavigationService.Navigate(new Uri("/ColetoresPage.xaml", UriKind.RelativeOrAbsolute));
}
else
{
MessageBox.Show("Preencha todos os campos e marque as opções para adicionar um coletor");
}
}
private void btnCancel_Click_1(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/ColetoresPage.xaml", UriKind.RelativeOrAbsolute));
}
}
}
Coletor class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;
namespace Aplicativo_Windows_Phone
{
#pragma warning disable 0169, 0649
[Table(Name = "Coletores")]
public class Coletor
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int Id { get; set; }
[Column]
public float Latitude { get; set; }
[Column]
public float Longitude { get; set; }
[Column(Name = "Pessoa")]
private int? pessoaId;
private EntityRef<Pessoa> _pessoa = new EntityRef<Pessoa>();
[Association(Name = "FK_Coletores_ColetorPessoa", IsForeignKey = true, Storage = "_pessoa", ThisKey = "pessoaId")]
public Pessoa Pessoa
{
get { return _pessoa.Entity; }
set { _pessoa.Entity = value; }
}
private EntitySet<Ocorrencia> _ocorrencias = new EntitySet<Ocorrencia>();
[Association(Name = "FK_Ocorrencias_ColetorOcorrencias", Storage = "_ocorrencias", ThisKey = "Id", OtherKey = "coletorId")]
public ICollection<Ocorrencia> Ocorrencias
{
get { return (from co in ColetorOcorrencias select co.Ocorrencia).ToList(); }
set { _ocorrencias.Assign(value); }
}
private EntitySet<PessoaColetor> _pessoaColetores = new EntitySet<PessoaColetor>();
[Association(Name = "FK_PessoaColetores_Coletores", Storage = "_pessoaColetores", OtherKey = "coletorId", ThisKey = "Id")]
private ICollection<PessoaColetor> PessoaColetores
{
get { return _pessoaColetores; }
set { _pessoaColetores.Assign(value); }
}
private EntitySet<ColetorOcorrencia> _coletorOcorrencias = new EntitySet<ColetorOcorrencia>();
[Association(Name = "FK_ColetorOcorrencias_Coletores", Storage = "_coletorOcorrencias", OtherKey = "coletorId", ThisKey = "Id")]
private ICollection<ColetorOcorrencia> ColetorOcorrencias
{
get { return _coletorOcorrencias; }
set { _coletorOcorrencias.Assign(value); }
}
public ICollection<Pessoa> Pessoas
{
get { return (from pc in PessoaColetores select pc.Pessoa).ToList(); }
}
}
}
根据过去的经验,这里要冒险。 SqlServerCE 驱动程序有两种版本,x86 和 x64。通常,机器上只能安装一个,安装程序将在第二个上失败。但是,如果先安装 x86 驱动程序,然后再安装 x64,则可以在命令行上使用 /force 开关。
这可能对您的问题有帮助,也可能没有帮助,从提供的详细信息很难判断。
好的,我不知道为什么,但现在我的应用程序可以运行了。我认为这个错误是 Visual Studio 的一种错误,所以,为了解决我的问题,我刚刚重新启动了我的电脑。