저는 초보 프로그래머입니다. 내 Windows phone mango app에 데이터베이스 파일 (MyDatabase.sdf)이 있습니다. 달성하려는 일은 격리 된 저장소에서 MyDatabase.sdf 파일을 복사하여 MyDatabaseBackup.txt로 변환 한 다음 백업으로 skydrive에 업로드하는 것입니다. skydrive는 업로드 할 .sdf 파일을 지원하지 않으므로 일부 사람들은이 변환 방법을 제안하여 작동하도록했습니다. 동일한 작업을 수행하려고하지만 .sdf 파일을 격리 된 저장소의 .txt 파일로 복사 할 수 없습니다. 여기 내 코드가 있습니다 ...데이터베이스 (.sdf) 파일을 skydrive로 백업하여 .txt로 변경합니다.
//START BACKUP
private void Backup_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 you want to backup? This will overwrite your old backup file!", "Backup?", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
UploadFile();
}
}
public void UploadFile()
{
if (skyDriveFolderID != string.Empty) //the folder must exist, it should have already been created
{
this.client.UploadCompleted
+= new EventHandler<LiveOperationCompletedEventArgs>(ISFile_UploadCompleted);
infoTextBlock.Text = "Uploading backup...";
dateTextBlock.Text = "";
using (AppDataContext appDB = new AppDataContext(AppDataContext.DBConnectionString))
{
appDB.Dispose();
}
try
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists("MyDatabase.sdf"))
{
myIsolatedStorage.CopyFile("MyDatabase.sdf", "MyDatabaseBackup.txt"); //This is where it goes to the catch statement.
}
this.client.UploadAsync(skyDriveFolderID, fileName, true, readStream , null);
}
}
catch
{
MessageBox.Show("Error accessing IsolatedStorage. Please close the app and re-open it, and then try backing up again!", "Backup Failed", MessageBoxButton.OK);
infoTextBlock.Text = "Error. Close the app and start again.";
dateTextBlock.Text = "";
}
}
}
private void ISFile_UploadCompleted(object sender, LiveOperationCompletedEventArgs args)
{
if (args.Error == null)
{
infoTextBlock.Text = "Backup complete.";
dateTextBlock.Text = "Checking for new backup...";
//get the newly created fileID's (it will update the time too, and enable restoring)
client = new LiveConnectClient(session);
client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(getFiles_GetCompleted);
client.GetAsync(skyDriveFolderID + "/files");
}
else
{
this.infoTextBlock.Text =
"Error uploading file: " + args.Error.ToString();
}
}
다음은 app.xaml.cs 파일에서 데이터베이스를 만드는 방법입니다.
// Specify the local database connection string.
string DBConnectionString = "Data Source=isostore:/MyDatabase.sdf";
// Create the database if it does not exist.
using (AppDataContext appDB = new AppDataContext(AppDataContext.DBConnectionString))
{
if (appDB.DatabaseExists() == false)
{
//Create the database
appDB.CreateDatabase();
appDB.SubmitChanges();
}
}
"프로세스/함수/스레드에 sdf 파일이 열려 있지 않은지 확인하십시오." 나는 UploadFile() 메서드에서 그걸 시도했지만 제대로했다면 완전히 확신 할 수 없다.
누군가이 두 가지 문제에 대한 코드 도움을 제공 할 수 있습니까? 도와 주셔서 감사합니다!