我正在开发一些在SQL服务器之间传输数据的代码。在这个阶段,我的所有工作都在同一台服务器上(本地,我是所有者),但我已经在尝试实现将在生产时使用的OPENROWSET功能(数据将在不同的服务器和我所在的位置)将不得不为转移建立查询)。以下3个代码应该做同样的事情,但是使用OPENROWSET的那个代码给了我一个错误...... Bref,我被卡住了!如果有人可以帮忙......
3部分命名:工作
USE db1
SELECT * INTO dbo.myTable FROM db2.dbo.myTable
OPENDATASOURCE:工作
USE db1
SELECT * INTO dbo.myTable FROM OPENDATASOURCE
('SQLOLEDB',
'Data Source=127.0.0.1\SQLEXPRESS;Integrated Security=SSPI'
).db2.dbo.myTable
OPENROWSET:不起作用
USE db1
SELECT * INTO dbo.myTable FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=(Local)',
'db2.dbo.myTable')
我收到以下消息:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.".
当然我试图使用我的连接字符串的标准属性(与OPENDATASOURCE一样),但我也收到以下错误:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid authorization specification".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid connection string attribute".
答案 0 :(得分:0)
首先:您的OPENROWSET
语句未指定服务器实例。
尝试
USE db1
SELECT * INTO dbo.myTable FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=127.0.0.1\SQLEXPRESS',
'db2.dbo.myTable')