2012-11-05 7 views
-3
using (EntityDataContext amdb = new EntityDataContext(StrConnectionString)) 
      { 
       if (amdb.DatabaseExists()) 
       { 
        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) 
        { 
         if (!isoStore.FileExists(databaseName)) 
         { 
          copyDatabase = true; 
         } 
         else 
         { 
          using (IsolatedStorageFileStream databaseStream = isoStore.OpenFile(databaseName, FileMode.Open, FileAccess.Read)) // error here 
          { 
           using (Stream db = Application.GetResourceStream(new Uri(databaseName, UriKind.Relative)).Stream) 
           { 
            if (databaseStream.Length < db.Length) 
             copyDatabase = true; 
           } 
          } 
         } 
        } 
       } 
       else 
       { 
        //error with the database that has been packaged 
       } 
       if (copyDatabase) 
        new Worker().Copy(databaseName); 
      } 
+0

질문의 제목은 예외입니다 ( – 1Mayur

+0

). 처음으로 t가 발생합니다. ime 에뮬레이터가 실행 된 후 닫을 때까지 계속 실행됩니다. – 1Mayur

+0

코드를 게시하는 것이 아니라 질문 자체에이 정보를 포함해야합니다. ** 코드가 무엇을하려고하고 무엇이 잘못되었는지 설명하십시오. – ChrisF

답변

0

격리 된 저장소 액세스 모드 매개 변수에서 읽을 수있는 대신 데이터를 쓸 수 있는지 확인하십시오.

기기로 테스트 했습니까?

+0

처음 에뮬레이터를 실행할 때 오류가 발생합니다. 그 후에 닫을 때까지 제대로 작동합니다. – 1Mayur

0

데이터베이스 연결을 열어 둔 상태에서 데이터베이스 파일을 읽으 려한다고 말할 수 있습니다. DataContext는 데이터베이스 (따라서 파일)를 잠그기 때문에 동시에 읽을 수 없습니다. 고립 된 스토리지 액세스 기능을 이동하여

bool shouldCopyDatabase = false; 
bool databaseExists = false; 

using (EntityDataContext amdb = new EntityDataContext(StrConnectionString)) 
{ 
    databaseExists = amdb.DatabaseExists(); 
} 

if (databaseExists == true) 
{ 
    using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     if (!isoStore.FileExists(databaseName)) 
     { 
      copyDatabase = true; 
     } 
     else 
     { 
      using (IsolatedStorageFileStream databaseStream = isoStore.OpenFile(databaseName, FileMode.Open, FileAccess.Read)) // error here 
      { 
       using (Stream db = Application.GetResourceStream(new Uri(databaseName, UriKind.Relative)).Stream) 
       { 
        if (databaseStream.Length < db.Length) 
         copyDatabase = true; 
       } 
      } 
     } 
    } 
} 

if (copyDatabase) 
    new Worker().Copy(databaseName); 

: 데이터베이스 연결을 사용하여 문을 닫으면

이런 식으로 뭔가를 시도 amdb.Close()를 호출하거나으로합니다 (EntityDataContext 개체를 닫으려고 종료하기 위해

using (EntityDataContext amdb = new EntityDataContext(StrConnectionString)) 범위를 벗어나면 데이터베이스 연결을 먼저 닫을 수 있습니다.

관련 문제