C# Sqlite 질문드립니다!!

public void LoadROIYPositions()
{
int module, posY;

        var connectionString = new SqliteConnectionStringBuilder(/*baseConnectionString*/)
        {
            DataSource = Common.DataBase_Path + "config.db",
            Mode = SqliteOpenMode.ReadOnly,
            Password = m_pMainForm.DBPassword
        }.ToString();

        module = posY = 0;
        using (var connection = new SqliteConnection(connectionString))
        {
            try
            {
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText =
                @"
                    SELECT
                        MODULE_NO, VALUE
                    FROM roi_y_positions
                    ORDER BY MODULE_NO
                ";

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        module = reader.GetInt16(0);
                        posY = reader.GetInt16(1);
                        ROIs[module] = posY;
                    }
                }
            }
            catch (SqliteException myException)
            {
                Common.GLog(LogLevel.ERROR, ClassName, "LoadROIYPositions Exception: " + myException);
            }
        }
    }

이 소스로 암호화 되어있는 config.db파일을 사용중인데
connection.Open();
이부분에서 시간을 한 3초정도를 잡아먹는데 왜그럴까요?ㅠㅠ

재현할 수 있는 소스 코드를 공유 하시면 아마 원하는 답을 얻을 수 있을 것 같습니다.

db 사이즈가 좀 큰가요?
사이즈가 크면 처음에 로드할때인가? 느리더라고욥ㅎㅎㅎ

아니요 ㅠㅠ 사이즈는 16kb 정도밖에 되지 않습니다 ㅠ 암호화를 해놓은 상태라서 그럴까요…

암호화 모듈은 어떤거 사용하셨나요?
저도 비슷한 경험 있었는데 암호화 모듈을 다른것으로 변경하니 잘 되더라고요.
그래서 지금은 SQLitePCLRaw를 사용하고 있습니다.

1개의 좋아요

저도 SQLitePCL.raw를 사용중입니답!

암호화는

private bool EncryptDBFile(string dbNameFullPath, string passwordToSet)
{
var connectionString = new SqliteConnectionStringBuilder()
{
DataSource = dbNameFullPath,
Mode = SqliteOpenMode.ReadWriteCreate,
Password = “”
}.ToString();

        using (var connection = new SqliteConnection(connectionString))
        {
            try
            {
                connection.Open();
                var databaseName = Path.GetFileNameWithoutExtension(dbNameFullPath);
                var databaseTemp = $"{databaseName}_Temp.db";
                File.Delete(databaseTemp);
                var query =
                    $"ATTACH DATABASE '{databaseTemp}' AS encrypted KEY '{passwordToSet}'; SELECT sqlcipher_export('encrypted'); DETACH DATABASE encrypted;";

                var cmd = new SqliteCommand(query, connection);
                cmd.ExecuteNonQuery();

                // https://stackoverflow.com/questions/8511901/system-data-sqlite-close-not-releasing-database-file
                connection.Close();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                cmd.Dispose();
                SqliteConnection.ClearAllPools();

                if (File.Exists(dbNameFullPath))
                {
                    File.Delete(dbNameFullPath);
                }

                File.Move(databaseTemp, dbNameFullPath);
            }
            catch (Exception ex)
            {
                if (ex is SqliteException)
                {
                    Common.GLog(LogLevel.ERROR, ClassName, $"EncryptDBFile Error:{ex.Message}");
                }
                else
                {
                    Common.GLog(LogLevel.ERROR, ClassName, $"EncryptDBFile Error2:{ex.Message}");
                }
                return false;
            }
        }
        return true;
    }

이런식으로 사용중인데 같을까요?ㅠㅠ

테스트 해보니까 암호화 전에는 지연이 없는데

암호화 후에 지연이 생기네요…