データベースのアップロードとダウンロードに Microsoft Live API を使用しています。しかし、とにかくデータベースにアクセスしようとした場合、ダウンロードまたはアップロードした後、私のアプリは SqlCeException Unhandled & exits を返します。データベースにアクセスする前にアプリを再起動してもエラーは発生しないので、今のところ解決策は
アプリケーションを再起動します
これは私のコードです
IsolatedStorageFileStream fileStream = null;
private void Upload_Click(object sender, RoutedEventArgs e)
{
if (client == null || client.Session == null)
{
MessageBox.Show("You Must Sign In First.");
}
else
{
if (MessageBox.Show("Are You Sure? This Will Overwrite Your Old Backup File!", "Backup?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
UploadDatabase();
}
}
}
public void UploadDatabase()
{
if (SDFolderID != string.Empty)
{
WLInfo.Text = "Uploading Backup...";
this.client.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(ISFile_UploadCompleted);
try
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
fileStream = store.OpenFile("DB.sdf", FileMode.Open, FileAccess.Read);
client.UploadAsync(SDFolderID, "DB.sdf", fileStream, OverwriteOption.Overwrite);
WLInfo.Text = "Upload Complete.";
}
}
catch
{
WLInfo.Text = "Error: Restart Application.";
}
}
}
private void ISFile_UploadCompleted(object sender, LiveOperationCompletedEventArgs args)
{
if (args.Error == null)
{
client = new LiveConnectClient(session);
client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(GetFiles_GetCompleted);
client.GetAsync(SDFolderID + "/files");
}
else
{
this.WLInfo.Text = "Error Uploading Backup File.";
}
fileStream.Close();
}
void GetFiles_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
{
List<object> data = (List<object>)e.Result["data"];
foreach (IDictionary<string, object> content in data)
{
if (((string)content["name"]).Equals(FileName))
{
FileID = (string)content["id"];
}
}
if (FileID != null)
{
WLInfo.Text = "Backup Found On Sky Drive.";
}
else
{
WLInfo.Text = "Backup Not Found On Sky Drive.";
}
}