以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 关于 sqlBulkCopy 执行报错【已解决】 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=188466) |
-- 作者:km007 -- 发布时间:2023/9/21 11:53:00 -- 关于 sqlBulkCopy 执行报错【已解决】 Dim dt As DataTable = DataTables("TableA") Dim conStr As String = "server=192.168.0.100,1433;uid=sa;pwd=Aa123456;database=ceshi2023" Dim tran As System.Data.SqlClient.SqlTransaction Dim conn As New System.Data.SqlClient.SqlConnection(conStr) Try Dim st As Date = Date.Now \'计算耗时 conn.Open() \'执行到这里会报错 [此贴子已经被作者于2023/9/21 14:42:00编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/9/21 12:00:00 -- 如果连接字符串没有问题,这句代码不可能出错的,检查其它代码 |
-- 作者:km007 -- 发布时间:2023/9/21 13:52:00 -- Dim dt As DataTable = DataTables("TableA") Dim conStr As String = "server=192.168.0.100,1433;uid=sa;pwd=Aa123456;database=ceshi2023" Dim tran As System.Data.SqlClient.SqlTransaction Dim conn As New System.Data.SqlClient.SqlConnection(conStr) Try Dim st As Date = Date.Now \'计算耗时 conn.Open() …… Catch ex As exception tran.Rollback() \'找到原因了,是这句报的错 MessageBox.Show("批量插入失败,原因:" & ex.message) Finally conn.Close() \'必须关闭,否则内存会一直泄露 End Try |
-- 作者:有点蓝 -- 发布时间:2023/9/21 13:54:00 -- 这个代码根本就没有用到事务,去掉即可 |
-- 作者:km007 -- 发布时间:2023/9/21 13:56:00 -- Dim dt As DataTable = DataTables("TableA") Dim conStr As String = "server=192.168.0.100,1433;uid=sa;pwd=Aa123456;database=ceshi2023" Dim tran As System.Data.SqlClient.SqlTransaction Dim conn As New System.Data.SqlClient.SqlConnection(conStr) Try Dim st As Date = Date.Now \'计算耗时 conn.Open() tran = conn.BeginTransaction()\'开始事务 …… Catch ex As exception tran.Rollback() \'找到原因了,是这句报的错 MessageBox.Show("批量插入失败,原因:" & ex.message) Finally conn.Close() \'必须关闭,否则内存会一直泄露 End Try
|
-- 作者:有点蓝 -- 发布时间:2023/9/21 14:05:00 -- Dim tran As System.Data.SqlClient.SqlTransaction Dim conn As New System.Data.SqlClient.SqlConnection(conStr) Dim st As Date = Date.Now \'计算耗时 conn.Open() tran = conn.BeginTransaction()\'开始事务 Try |
-- 作者:km007 -- 发布时间:2023/9/21 14:13:00 -- 解决了 Dim tran As System.Data.SqlClient.SqlTransaction Dim conn As New System.Data.SqlClient.SqlConnection(conStr) Try conn.Open() \'打开链接 Catch ex As exception conn.Close() \'必须关闭,否则内存会一直泄露 MessageBox.Show("链接服务器失败,原因:" & ex.message) Return Nothing End Try Try Dim st As Date = Date.Now \'计算耗时 tran = conn.BeginTransaction()\'开始事务
|