using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["textconnstring"].ToString())) { if (conn.State == ConnectionState.Closed) conn.Open(); SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadUncommitted); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sqlStr1; cmd.Transaction = trans; cmd.ExecuteNonQuery(); cmd.CommandText = sqlStr2; cmd.Transaction = trans; cmd.ExecuteNonQuery(); using (SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["textconnstring"].ToString())) { SqlCommand cmd1 = new SqlCommand(sqlStr, conn1); SqlDataAdapter sda = new SqlDataAdapter(cmd1); DataSet ds =new DataSet(); sda.Fill(ds); } trans.Commit(); }catch(SqlException ex) { trans.Rollback(); Console.WriteLine(ex.Message); } }
其中sqlStr1和 sqlStr2为插入语句,sqlStr为查询语句。conn和conn2是两个不同的连接,但是在执行时到了“sda.Fill(ds)”时程序会卡住,然后就是超时错误了,不知是什么原因?
- 4 回答
- 0 关注
- 458 浏览
添加回答
举报
0/150
提交
取消