C# SQLite-Insert命令对1200条记录执行10秒
我在transacion上使用参数化命令插入1300条记录。 我在一个uniq列上有一个索引,但即使我删除索引,这仍然需要10秒 这是我的连接字符串:C# SQLite-Insert命令对1200条记录执行10秒,c#,database,sqlite,insert,C#,Database,Sqlite,Insert,我在transacion上使用参数化命令插入1300条记录。 我在一个uniq列上有一个索引,但即使我删除索引,这仍然需要10秒 这是我的连接字符串: using (SQLiteTransaction trans = sql_con.BeginTransaction()) { commandInsert.Transaction = trans; commandInsert.Parameters["@One"].Value = "ONE"; commandInsert.P
using (SQLiteTransaction trans = sql_con.BeginTransaction())
{
commandInsert.Transaction = trans;
commandInsert.Parameters["@One"].Value = "ONE";
commandInsert.Parameters["@Two"].Value = "TWO";
commandInsert.Parameters["@Three"].Value = "THREE";
commandInsert.Parameters["@Four"].Value = "FOUR";
commandInsert.Parameters["@FIVE"].Value = "FIVE";
commandInsert.Parameters["@SIX"].Value = "SIX";
commandInsert.Parameters["@SEVEN"].Value = "SEVEN";
commandInsert.Parameters["@EIGHT"].Value = "EIGHT";
commandInsert.Parameters["@NINE"].Value = "NINE";
commandInsert.Parameters["@TEN"].Value = "TEN";
commandInsert.Parameters["@ELEVEN"].Value = "ELEVEN";
commandInsert.Parameters["@CommentCount"].Value =
commandInsert.Parameters["@NUMBER1"].Value = 5;
commandInsert.Parameters["@NUMBER2"].Value = 6;
commandInsert.Parameters["@NUMBER3"].Value = 8;
commandInsert.ExecuteNonQuery();
trans.Commit();
}
我怎样才能加快速度
编辑
问题解决了。。。
问题在于检测语言而不是插入(需要3毫秒)。
很抱歉占用了您的时间…如果您使用的是SQL server,您可以在SQL语句中使用“显示估计的执行计划”来查找是否有一个部分占用了比另一个部分更多的资源。例如,如果您使用select查询的结果来填充表,则带有复杂联接的select可能会减慢速度。我的观点是,您可以将命令移植到sql server中进行尝试,SQLite没有合适的配置,它将告诉他sql server将如何执行它,而不是SQLite。@StevenWood SQLite有。无论如何,执行计划对简单的insert语句没有帮助。查看您的代码段,您似乎正在为每个insert启动一个事务,而不是为所有1300条记录启动一个事务。你试过了吗?代码不完整/不是你的实际代码。请发布您的真实代码或完整示例,以生成您的结果。在这个(不可编译的)截取之后,我们看不到您在哪里以及如何循环记录。您在表上放了多少索引?
string ConnectionString =
"Data Source=Data/database.db3;Version=3;Compress=True;Count Changes=off;Journal Mode=off;Pooling=true;" +
"Cache Size=10000;Page Size=4096;Synchronous=off";