求助 报错 OracleConnection does not support parallel transactions.
这段代码 哪里有错吗? 为啥会报这种错误 求大神解答
private void button2_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filepath = folderBrowserDialog1.SelectedPath;
DirectoryInfo dir = new DirectoryInfo(filepath);
FileInfo[] fis = dir.GetFiles();
using (OracleConnection conn = new OracleConnection(OracleHelper.ConnectionStrings))
{
try
{
conn.Open();
OracleCommand cmd = null;
OracleTransaction transaction = null;
int j = 0;
for (int i = 0; i < fis.Length; i++)
{
string filename = fis[i].Name;
if (j == 0)
{
cmd = conn.CreateCommand();
cmd.Connection.BeginTransaction();
cmd.Transaction = transaction;
}
try
{
//cmd.CommandText = "update SZJT_ZJ_ZJSJ_B set wjnr=:WJNR where jh=" + "'"+filename.Split('钻')[0]+"'";
cmd.CommandText = "select wjnr from SZJT_ZJ_ZJSJ_B where jh=" + "'" + filename.Split('钻')[0] + "' for update";
OracleDataReader reader = cmd.ExecuteReader();
using (reader)
{
reader.Read();
OracleLob tempLob = reader.GetOracleLob(0);
FileStream fs = new FileStream(filepath+"\\"+filename, FileMode.Open);
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
int length = 10485760;
byte[] Buffer = new byte[length];
//int i = 0;
while ((i = fs.Read(Buffer,0,length)) > 0)
{
tempLob.Write(Buffer,0,i);
}
fs.Close();
tempLob.EndBatch();
cmd.Parameters.Clear();
}
FileStream fs1 = null;
StreamWriter sw1 = null;
if (File.Exists(filepath + "\\" + "log.txt"))
{
fs1 = new FileStream(filepath + "\\" + "log.txt", FileMode.Append, FileAccess.Write);
}
else
{
fs1 = new FileStream(filepath + "\\" + "log.txt", FileMode.Create, FileAccess.Write);
}
sw1 = new StreamWriter(fs1);
sw1.WriteLine(filename);
sw1.Close();
fs1.Close();
j++;
if (j == 20 || j == fis.Length % 20)
{
transaction.Commit();
cmd.Dispose();
j = 0;
}
}
catch(Exception ex1)
{
this.textBox1.Text = this.textBox1.Text + filename + Environment.NewLine;
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
}
}