public SQLiteConnection conn = new SQLiteConnection();
public SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
public DbTransaction trans;
public void Initialize(string FileName)
{
connstr.DataSource = FileName;
if (conn.ConnectionString != connstr.ToString())
{
conn.Close();
}
if (conn.State != ConnectionState.Open)
{
conn.ConnectionString = connstr.ToString();
conn.Open();
}
}
public DataTable OpenDataTable(string Sql, string TName)
{
DataTable TT = new DataTable(TName);
try
{
if (TName == “”)
{
return TT;
}
SQLiteCommand Com = new SQLiteCommand(Sql);
Com.Connection = conn;
SQLiteDataAdapter Adp = new SQLiteDataAdapter(Com);
TT.RemotingFormat = SerializationFormat.Binary;
TT.CaseSensitive = true;
//Adp.FillSchema(TT, SchemaType.Source);
Adp.Fill(TT);//此處報錯
Com.Dispose();
Adp.Dispose();
}
catch (System.Exception ex)
{
}
return TT;
}
C#採用多線程調用OpenDataTable會報錯
1.Connection was closed, statement was terminated
2.library routine called out of sequence null connection or database handle
public SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
public DbTransaction trans;
public void Initialize(string FileName)
{
connstr.DataSource = FileName;
if (conn.ConnectionString != connstr.ToString())
{
conn.Close();
}
if (conn.State != ConnectionState.Open)
{
conn.ConnectionString = connstr.ToString();
conn.Open();
}
}
public DataTable OpenDataTable(string Sql, string TName)
{
DataTable TT = new DataTable(TName);
try
{
if (TName == “”)
{
return TT;
}
SQLiteCommand Com = new SQLiteCommand(Sql);
Com.Connection = conn;
SQLiteDataAdapter Adp = new SQLiteDataAdapter(Com);
TT.RemotingFormat = SerializationFormat.Binary;
TT.CaseSensitive = true;
//Adp.FillSchema(TT, SchemaType.Source);
Adp.Fill(TT);//此處報錯
Com.Dispose();
Adp.Dispose();
}
catch (System.Exception ex)
{
}
return TT;
}
C#採用多線程調用OpenDataTable會報錯
1.Connection was closed, statement was terminated
2.library routine called out of sequence null connection or database handle
解决方案
40
你这个思维方式,纠结外道而不深入一点点去抽象建模理解知识,很容易产生分裂。就好像小孩子发现本人的舌头能尝五味,就幼稚地纠结于本人到底是不是长着5个小舌头。这时候就需要提高抽象认识水平,知道程序运行存在着的多个 Dbconnection 对象,而不是仅仅知道“连接的数据库”。