Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据库被C的SQLite DLL锁定#_C#_Database_Sqlite_Database Locking - Fatal编程技术网

C# 数据库被C的SQLite DLL锁定#

C# 数据库被C的SQLite DLL锁定#,c#,database,sqlite,database-locking,C#,Database,Sqlite,Database Locking,我有以下代码: public Dictionary<long, List<long>> CloneGroupMeasuredOutputs(ISimulation clonedSimulation, Dictionary<long, long> crashDict, Dictionary<long, long> outputDict, string variationIDs, ProgressInterface progressInterface

我有以下代码:

 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();
            }
        }
    }

谢谢大家!

这可能是因为您试图在连接上执行另一个命令,而该连接仍在通过DataReader读取


当datareader仍有更多可用数据时(除非数据库支持多个活动结果集——MARS),不能使用连接执行更多命令,而Sqlite可能不支持。这意味着您必须在执行另一个命令之前读取整个第一个结果,或者使用不同的连接来执行此操作。

我发现您在读取时无法插入。因此,您必须阅读所有内容,然后才能插入。
_sqlInsertRowIntoMeasuredOutputs = @"INSERT INTO MeasuredOutputs (Value,RunIndex,CrashId,OutputId,VariationIndex,SimulationId) VALUES({0},{1},{2},{3},{4},{5}); SELECT last_insert_rowid()";