는 우리가하는 일입니다. 그것은 내용으로 포함되어 있습니다, 항상 프로젝트에서 복사하십시오.
사용자 컴퓨터에서이 파일은 특수 디렉터리 Environment.SpecialFolder.Personal
에 저장됩니다.
앱이 시작되면 사용자 시스템에 데이터베이스가 있는지 확인하고, 그렇지 않은 경우 데이터베이스에 복사합니다.
연결 문자열은 단지 "Data Source=" + sDatabasePath
입니다. 여기
우리가이를 위해 사용하는 코드의 샘플은 (우리가 DB를 관리하기위한 및 자작 클래스를 사용하기 때문에 내가 연결 물건 해킹, 그러나 당신은 생각을해야합니다)입니다 :
const string DATABASE_FILE_NAME = "MyDB.db3";
bool fSuccess = false;
DbConnection conn = new DbConnection();
string sApplicationDir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "MyApplicationSubDir");
if (!Directory.Exists (sApplicationDir)) {
Directory.CreateDirectory (sApplicationDir);
}
// Generate the directory to the database file
string sDatabaseDir = Path.Combine (sApplicationDir, "Database");
m_sDatabaseDir = sDatabaseDir;
if (!Directory.Exists (sDatabaseDir)) {
Directory.CreateDirectory (sDatabaseDir);
}
// Generate the path to the database file
string sDatabasePath = Path.Combine (sDatabaseDir, DATABASE_FILE_NAME);
m_sDatabaseFile = sDatabasePath;
// If the file does not not exist
if (!File.Exists (sDatabasePath)) {
// Copy the base implementation
File.Copy (Path.Combine (Path.Combine (Environment.CurrentDirectory, "Database"), DATABASE_FILE_NAME), sDatabasePath);
}
// Initialize the DB
conn.ConnectionString = "Data Source=" + sDatabasePath;
정보 주셔서 감사합니다. 내 질문에 대답하기 위해, 나는 1) DB 파일을 UI 프로젝트에 넣는다. 2) 설정 파일이 없다. – user472292
네, 맞습니다. –