亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

執行下面代碼會有超時異常?

執行下面代碼會有超時異常?

牛魔王的故事 2018-12-07 06:48:17
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 回答

?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

你的把 conn1.Close() 放到 trans.Commit(); 的后面.

查看完整回答
反對 回復 2019-01-21
?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

cmd1.CommandTimeout=0就好了

查看完整回答
反對 回復 2019-01-21
  • 4 回答
  • 0 關注
  • 489 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號