我在通过vb.net将使用SQL Server Management Studio进行的SQL转储发送到另一个SQL Server时遇到了一个大问题。我制作了这样的SQL文件:数据库/任务/脚本...
删除转储中的每个“ GO”命令后,我设法将其上载到本地SQL-Server2012。但这仅在我为任何表创建了不同脚本的情况下才有效。如果我使用一个大文件,则会超时。
现在,我想通过Internet连接将数据(50 MB)传输到另一个SQL Server。此服务器上仅生成5个表中的3个:-(
我收到以下超时错误(德语版本,抱歉):
“ System.Data.dll中发生“ A System.Data.SqlClient.SqlException”异常(第一次机会)。超时到期。操作超时或服务器未响应。
任何想法哪一方造成超时(SQL-Server oder vb.net)?有没有更安全的方法将大量数据上传到SQL Server?
这是我使用的代码(SQL-Skript在My.Resources.SQLDump中):
'####SQLDump #######
Dim SQLscript As String = My.Resources.SQLDump
SQLscript = "USE [" + TextBoxDB.Text + "] " + vbCrLf + SQLscript
Using connection As New SqlConnection(Verbind.ConStr)
Using command As New SqlCommand()
' Set the connection
command.Connection = connection
' Not necessary, but good practice
command.CommandType = CommandType.Text
' Example query using parameters
command.CommandText = SQLscript
Try
connection.Open()
rowsAffected = command.ExecuteNonQuery()
Catch ex As Exception
Debug.Print(ex.Message)
Finally
command.Dispose()
connection.Dispose()
End Try
'command.ExecuteNonQuery()
End Using ' Dispose Command
End Using ' Dispose (and hence Close) Connection
MsgBox("DB-Upload 1/5 fertig!")
有没有更安全的方法将大量数据上传到SQL Server?
是的,有几种方法可以将数据加载到SQL Server中
重要说明:在64位计算机上,Integration Services将安装64位版本的SQL Server导入和导出向导(DTSWizard.exe)。但是,某些数据源(例如Access或Excel)仅具有32位提供程序。要使用这些数据源,您可能必须安装并运行32位版本的向导。若要安装32位版本的向导,请在安装过程中选择“客户端工具”或“ SQL Server数据工具(SSDT)”。
作为SSIS开发人员,我可以深入研究并演示使用SSIS导入数据的可能方法,例如
关于解决错误,您可以在代码中设置命令超时属性,以使其在任何特定时间限制或无限时间内运行。
command.CommandTimeout = 1;
注意:在异步方法调用(例如BeginExecuteReader)期间,将忽略CommandTimeout属性。
编辑这里是示例代码
Using command As New SqlCommand()
command.Connection = connection
command.CommandType = CommandType.Text
command.CommandText = SQLscript
command.CommandTimeout = 1
Try
connection.Open()
rowsAffected = command.ExecuteNonQuery()
Catch ex As Exception
Debug.Print(ex.Message)
Finally
command.Dispose()
connection.Dispose()
End Try
End Using
另一种方法是延长连接超时您在连接字符串。它接受表示秒的整数(在下面的示例中,连接超时设置为30秒; 0表示无限制)
连接超时= 30;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句