у меня есть этот код ниже:База данных заблокирована SQLite для библиотек в C#
public Dictionary<long, List<long>> CloneGroupMeasuredOutputs(ISimulation clonedSimulation, Dictionary<long, long> crashDict, Dictionary<long, long> outputDict, string variationIDs, ProgressInterface progressInterface)
{
{
Dictionary<long, List<long>> measuredOutputIndexes = new Dictionary<long, List<long>>();
DbDataReader reader = null;
long counter = 0;
string crashText = GetKeysList(crashDict);
string outputText = GetKeysList(outputDict);
int numberOfIterations = 50000;
//
var conn = ((RDB1Connection)this.DbConnection).RDB1DbConnection;
try
{
if (conn.State == ConnectionState.Closed) conn.Open();
DbCommand dbCommand = conn.CreateCommand();
dbCommand.Connection = conn;
dbCommand.CommandText = string.Format("CREATE INDEX IF NOT EXISTS MOIndexSCOVI ON MeasuredOutputs (SimulationId, CrashId, OutputId, VariationIndex)");
dbCommand.ExecuteNonQuery();
dbCommand.CommandText = string.Format(_sqlGetNumberOfSomeMeasuredOutputs, this.ID, crashText, outputText, variationIDs);
if (conn.State == ConnectionState.Closed) conn.Open();
long numberOfRows = (long)dbCommand.ExecuteScalar();
float step = (float)40.0/(numberOfRows/numberOfIterations + 1);
dbCommand.CommandText = string.Format(_sqlGetSomeMeasuredOutputs, this.ID, crashText, outputText, variationIDs);
if (conn.State == ConnectionState.Closed) conn.Open();
reader = dbCommand.ExecuteReader();
DbCommand ClonedSimulationDbCommand = ((RDB1Connection)clonedSimulation.DbConnection).DbProviderFactory.CreateCommand();
ClonedSimulationDbCommand.Connection = ((RDB1Connection)clonedSimulation.DbConnection).RDB1DbConnection;
if (clonedSimulation.IsConnectionClosed())
clonedSimulation.OpenConnection();
long _id;
List<long> measuredOutputsIds = null;
while (reader.Read())
{
var p0 = (double)reader["value"];
var p1 = (long)reader["runIndex"];
var p2 = crashDict[(long)reader["crashId"]];
var p3 = outputDict[(long)reader["outputId"]];
var p4 = (long)reader["variationIndex"];
ClonedSimulationDbCommand.CommandText = string.Format(_sqlInsertRowIntoMeasuredOutputs, p0, p1, p2, p3, p4, (long)clonedSimulation.ID);
measuredOutputsIds = new List<long>();
// p2.Value = crashId;
_id = (long)ClonedSimulationDbCommand.ExecuteScalar();
//_id = (long)dbCommand.ExecuteScalar();
measuredOutputsIds.Add(_id);
counter++;
measuredOutputIndexes.Add((long)reader["id"], measuredOutputsIds);
if (counter >= numberOfIterations)
{
counter = 0;
((RDB1Connection)clonedSimulation.DbConnection).CommitTransaction();
if (progressInterface.isCancelled())
{
reader.Close();
return null;
}
else
{
progressInterface.updateProgressWith(step);
}
//((RDB1Connection)clonedSimulation.DbConnection).BeginTransaction();
}
}
reader.Close();
((RDB1Connection)clonedSimulation.DbConnection).CommitTransaction();
return measuredOutputIndexes;
}
catch (Exception ex)
{
((RDB1Connection)clonedSimulation.DbConnection).RollbackTransaction();
throw ex;
}
finally
{
if (reader != null)
reader.Close();
}
}
}
На этой линии: _id = (длинный) ClonedSimulationDbCommand.ExecuteScalar(); я получаю исключение блокировки базы данных
Соединение открыто, путь к базе данных существует и действителен. Я думаю, что проблема, которую я открываю для соединений для одной и той же базы данных, может быть проблемой.
SQL-утверждение:
_sqlInsertRowIntoMeasuredOutputs = @"INSERT INTO MeasuredOutputs (Value,RunIndex,CrashId,OutputId,VariationIndex,SimulationId) VALUES({0},{1},{2},{3},{4},{5}); SELECT last_insert_rowid()";
Спасибо!
То, что я узнал, это то, что вы не можете вставить во время чтения. Поэтому вы должны прочитать все и после этого вставить. –