Public Function Ins_Del_Udp_Data_Table3(ByVal strSql1 As String, ByVal strSql2 As String, ByVal strTableName As String, ByVal m_table As DataTable) As Boolean
OpenConn()
Dim myTran As SqlTransaction = m_Conn.BeginTransaction
Dim m_Cmd As New SqlCommand
m_Cmd.CommandTimeout = 6000
m_Cmd.Transaction = myTran
m_Cmd.Connection = m_Conn
Try
m_Cmd.CommandText = strSql2
m_Cmd.ExecuteNonQuery()
m_Cmd.CommandText = strSql1
m_Cmd.ExecuteNonQuery()
Dim m_sqlbc As New System.Data.SqlClient.SqlBulkCopy(GlobalPro.strConnection)
m_sqlbc.BatchSize = 1000
m_sqlbc.DestinationTableName = strTableName
'm_sqlbc.BulkCopyTimeout = 6000
m_sqlbc.WriteToServer(m_table) ‘这句报错!!!!!超时!
myTran.Commit()
m_sqlbc.Close()
CloseConn()
Return True
Catch ex As Exception
myTran.Rollback()
CloseConn()
MessageBox.Show(ex.ToString)
Return False
End Try
End Function
很奇怪的问题,如果我的前面两个sql语句和后面的写入的操作分开在两个函数中执行的话就是正常的。
如果写到一起就就报超时错误(代码中已标注报错点)
PS
这个函数主要的功能就是先删除后添加
请问为什么?!!!!!
------解决方案--------------------
要用同一个Transaction
SqlBulkCopy sqlbulk = new SqlBulkCopy( m_Conn, SqlBulkCopyOptions.KeepIdentity, myTran);
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/