2013-04-08 3 views
6

C#에서 SQLite 연결을 여는 방법 in WAL mode? 당신이 덜 장황 뭔가를 알고 있다면WAL 모드에서 SQLite 연결을 여는 방법

SQLiteConnection connection = new SQLiteConnection("Data Source=" + file); 
connection.Open(); 
using (var command = new SQLiteCommand(sqliteConnection)) 
{ 
    command.CommandText = "PRAGMA journal_mode=WAL"; 
    command.ExecuteNonQuery(); 
} 
// (Perform my query) 

, 내가 듣고 행복 할 것 :

여기
SQLiteConnection connection = new SQLiteConnection("Data Source=" + file); 
connection.Open(); 
// (Perform my query) 

답변

10

SQLiteConnection 연결 문자열을 지정하는 방법은 어떻습니까? 예컨대

public static class Connection 
{ 
    public abstract SQLiteConnection NewConnection(String file); 
} 

public class NormalConnection : Connection 
{ 
    public override SQLiteConnection NewConnection(String file) 
    { 
    return new SQLLiteConneciton("Data Source=" + file); 
    } 
} 

public class WALConnection : Connection 
{ 
    public override SQLiteConnection NewConnection(String file) 
    { 
    return new SQLLiteConnection("Data Source=" + file + ";PRAGMA journal_mode=WAL;" 
    } 
} 

에 대한

코드를 테스트,하지만 난 당신이 그것을 사용할 때 그래서 당신은 그렇게 할 수있는, 당신은 아이디어를 얻을 수 있기를 바랍니다되지 않습니다.

new SQLiteConnection("Data Source=" + file + ";PRAGMA journal_mode=WAL;") 
+0

+1 코드의 마지막 줄 내가 찾고있는 솔루션입니다, 감사합니다 많이! 공장 접근 방식은 필자의 경우에는 필요하지 않지만 흥미로울 수있다. –

+1

귀하의 접근 방식은 SQLite 연결 문자열에 허용되는 매개 변수의 수를 감안할 때 조합에 대한 흥미로운 사례 연구입니다. – Mark

1

내보다 적게보다는 완벽한 솔루션입니다 : 나는 일반 모드에서 열 방법은 다음과

입니다 그것에 대해!

6

아래 라인은 내가 누구의 대답이 포함 가자미의 일종으로 많은 감사, 무엇을 찾고 있었다입니다 = WAL은 영속적입니다. 프로세스가 WAL 모드를 설정 한 다음 데이터베이스를 닫았다가 다시 열면 데이터베이스가 WAL 모드로 돌아갑니다. " 내가 제대로 이해한다면

http://www.sqlite.org/wal.html

, 이것은 당신이 모든 연결을 설정할 필요가 없습니다, 일단 데이터베이스에 대한 WAL 모드를 설정할 수 있다는 것을 의미한다.

당신은 SQLite는 대한 명령 행 쉘을 수행 할 수 있습니다 http://www.sqlite.org/sqlite.html

+0

왜 그에게 답을주지 않았습니까? – Mawg

+0

@Mawg : 네 말이 맞아. 난 그냥했다 :-) –

1

지속성 WAL 모드의 다른 저널링 모드와는 달리

"PRAGMA의 journal_mode을 :

SQLLiteConnection conWal = new WALConnection(file); 
    conWAL.Open(); 

    SQLLiteConnection conNormal = new NormalConnection(file); 
    conNormal.Open(); 
관련 문제