简体   繁体   English

从服务器复制表并插入另一台服务器:此T-SQL查询出了什么问题?

[英]Copy Table from a Server and Insert into another Server: What is wrong with this T-SQL query?

I am using SQL Server 2014 . 我正在使用SQL Server 2014 I have created the following T-SQL query which I uploaded to my local SQL server to run as a job process on a daily basis at a specific time. 我创建了以下T-SQL查询,该查询已上传到我的本地SQL服务器,以每天在特定时间作为作业过程运行。 However, I noticed that it failed to run. 但是,我注意到它无法运行。 If I run it manually in SSMS , it runs correctly. 如果我在SSMS手动运行它,则它可以正常运行。 What is preventing the query to run as an automated process? 是什么导致查询无法以自动化流程运行? Is it a syntax issue? 这是语法问题吗?

USE MyDatabase
GO

DELETE FROM ExchangeRate -- STEP 1

;WITH MAINQUERY_CTE AS ( --STEP 2
    SELECT *
    FROM (
        SELECT *
        FROM [178.25.0.20].HMS_ARL.dbo.ExchangeRate
    ) q

)
INSERT INTO ExchangeRate --STEP 3
SELECT *
FROM MAINQUERY_CTE

Basically, the function of the query is to copy a table named ExchangeRate from the live server and paste its content in a table of the same name (which already exists on my local server). 基本上,查询的功能是从实时服务器复制一个名为ExchangeRate的表,并将其内容粘贴到同名的表中(该表已经存在于我的本地服务器上)。

Error Log shows the following message: 错误日志显示以下消息:

Description: Executing the query "USE MyDatabase DELETE FROM ExchangeRate..." failed with the following error: "Access to the remote server is denied because no login-mapping exists.". 说明:执行查询“使用MyDatabase从ExchangeRate删除...”失败,并出现以下错误:“由于没有登录映射,对远程服务器的访问被拒绝。”。 Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. 可能的失败原因:查询问题,“ ResultSet”属性未正确设置,参数未正确设置或连接未正确建立。 End Error DTExec: The package execution returned DTSER_FAILURE (1). 结束错误DTExec:程序包执行返回DTSER_FAILURE(1)。 Started: 10:59:30 AM Finished: 10:59:30 AM Elapsed: 0.422 seconds. 开始:10:59:30 AM完成:10:59:30 AM经过:0.422秒。 The package execution failed. 程序包执行失败。 NOTE: The step was retried the requested number of times (3) without succeeding. 注意:步骤已重试要求的次数(3),但未成功。 The step failed. 该步骤失败。

也许您必须在本地服务器中创建到远程服务器的链接服务器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM