У меня есть следующий (упрощенный) код:
IDbConnection connection = new SQLiteConnection(GetConnectionString());
if (connection.State == ConnectionState.Closed)
connection.Open();
using (IDbTransaction transaction = connection.BeginTransaction())
{
using (IDbCommand cmd = transaction.Connection.CreateCommand())
{
cmd.CommandText = "DELETE FROM Records2 WHERE ClientIndex = @ClientIndex";
AddParameter(cmd, "@ClientIndex", DbType.Int32, clientIndex);
cmd.ExecuteNonQuery();
}
using (IDbCommand cmd = transaction.Connection.CreateCommand())
{
cmd.CommandText = "INSERT INTO Records2(ClientIndex, CandidateIndex, Name)";
cmd.CommandText += " VALUES(@ClientIndex, @CandidateIndex, @Name)";
AddParameter(cmd, "@ClientIndex", DbType.Int32, clientIndex);
IDbDataParameter pIndex = AddParameter(cmd, "@CandidateIndex", DbType.Int32, null);
IDbDataParameter pName = AddParameter(cmd, "@Name", DbType.AnsiString, null);
int index = 0;
foreach (Record record in records)
{
pIndex.Value = index++;
pName.Value = record.Name;
cmd.ExecuteNonQuery();
}
}
using (IDbCommand cmd = transaction.Connection.CreateCommand())
{
cmd.CommandText = "UPDATE Records SET Status = @Status, UpdateDate = @UpdateDate WHERE ClientIndex = @ClientIndex";
AddParameter(cmd, "@ClientIndex", DbType.Int32, clientIndex);
AddParameter(cmd, "@Status", DbType.Byte, status);
AddParameter(cmd, "@UpdateDate", DbType.DateTime, DateTime.Now);
cmd.ExecuteNonQuery();
}
transaction.Commit();
}
connection.Close();
с:
private IDbDataParameter AddParameter(IDbCommand command, string paramName, DbType type, object value)
{
IDbDataParameter parameter = command.CreateParameter();
parameter.ParameterName = paramName;
parameter.DbType = type;
if (value != null)
parameter.Value = value;
else
parameter.Value = DBNull.Value;
command.Parameters.Add(parameter);
return parameter;
}
Все ExecuteNonQueries работают без проблем, кроме последней. На моей машине (под управлением xp) я получаю следующее исключение, но на других машинах (под управлением Windows 7) это работает без проблем, с тем же кодом и тем же файлом базы данных.
SQLiteException (0x80004005): Unable to open the database file
System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt) +375
System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) +199
System.Data.SQLite.SQLiteDataReader.NextResult() +226
System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) +87
System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) +38
System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() +39
Я попытался использовать JournalMode = Perist в строке подключения и исключил каталог, содержащий файл базы данных, из моего антивируса, но ничего не помогло.
Я использую 3.5 Framework, и моя версия System.Data.SQLite - 1.0.66.0.
Есть идеи?
Заранее спасибо,
Марк