我有这段代码可以将数据从一个表插入到另一个表中。问题是我现在正试图从远程 mssql 服务器插入到我的本地 mssql 服务器的表中。使用 VB.net 的 sql 脚本将如何?
我目前收到一个错误:
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:TCP Provider,错误:0 - 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。)
这是我目前的代码:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rowsAffected As Integer = 0
Dim myConnectionString = "Data Source=(IP Address),1433;Network Library=DBMSSOCN;Initial Catalog=dbase;User ID=sa;Password=password;"
Dim myconnectionstring2 = "Data Source= PC-Name;Initial Catalog=dbase;Integrated Security=True;Pooling=False"
'Dim myConnection As New SqlConnection(myConnectionString)
Dim myQuery As String = "INSERT INTO dbase.dbo.tbltransactions1 SELECT * FROM dbase.dbo.tbltransactions1"
'Dim myQuery As String = "insert INTO (table)"
'select
'from LinkedserverName.DatabaseName.SchemaName.TableName"
Dim myCommand As New SqlCommand(myQuery, myConnection, myConnection2)
Try
myConnection.Open()
rowsAffected = myCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox(" ")
Finally
myConnection.Close()
End Try
Label1.Text = rowsAffected.ToString()
End Sub
*具有IP地址的连接字符串是我要连接的服务器,而另一个是我本地服务器的连接字符串..