[英]Could not find server ‘DATABASE_NAME′ in sys.servers error
The code below is embedded in a .sql file in a vb.net project. 下面的代码嵌入在vb.net项目的.sql文件中。 It gives me an error:
它给了我一个错误:
Could not find server 'DATABASE_NAME′ in sys.servers. 无法在sys.servers中找到服务器“DATABASE_NAME”。 Verify that the correct server name was specified.
验证是否指定了正确的服务器名称。 If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
如有必要,执行存储过程sp_addlinkedserver以将服务器添加到sys.servers。
I checked in sys.server and the LinkedDatabaseName is returned if i do a select * from sys.servers 我检查了sys.server,如果我从 sys.servers执行select *,则会返回LinkedDatabaseName
Here is the code where I get the error.... 这是我得到错误的代码....
-----------------------------------
-- Obs Set Obs Set Obs Item Xref
-----------------------------------
-- STEP 1: txmr_TABLE1 to exp_TABLE1
DELETE FROM LinkedDatabaseName...exp_TABLE1
Select distinct newid() as GUID,
b.ObsSetCode as 'parObsSetCode',
c.ObsSetCode as 'chObsSetCode',
d.ObsItemCode as 'chObsItemCode'
Into #tmp_exp_TABLE1
From $$DATABASE_NAME$$..txmr_TABLE1 a
Inner Join $$DATABASE_NAME$$..txmr_obs_set b On a.parObsSetGUID = b.GUID
Left Join $$DATABASE_NAME$$..txmr_obs_set c On a.chObsSetGUID = c.GUID
Left Join $$DATABASE_NAME$$..txmr_obs_item d On a.chObsItemGUID = d.GUID
Order By b.ObsSetCode
Select * From #tmp_exp_TABLE1
EXEC $$DATABASE_NAME$$..dbo.txmr_ExtractPOCIS '#tmp_exp_TABLE1',
'$$DATABASE_NAME$$.dbo.txmr_TABLE1_chg',
@FromVersion,
@ToVersion;
INSERT INTO LinkedDatabaseName...exp_TABLE1 (GUID, parObsSetCode, chObsSetCode, chObsItemCode)
SELECT GUID, parObsSetCode, chObsSetCode, chObsItemCode
FROM #tmp_exp_TABLE1
ORDER BY parObsSetCode, chObsSetCode;
DROP TABLE #tmp_exp_TABLE1;
SELECT COUNT(*), 'exp_TABLE1' FROM LinkedDatabaseName...exp_TABLE1;
-- STEP 2: txmr_TABLE1_chg to exp_TABLE1_chg
DELETE FROM LinkedDatabaseName...exp_TABLE1_chg;
INSERT INTO LinkedDatabaseName...exp_TABLE1_chg (ChangeID, DateModified, parObsSetCode, chObsSetCode, chObsItemCode, RationaleLink, RationaleFreeText)
SELECT a.GUID as 'ChangeID',
a.DateModified as 'DateModified',
b.ObsSetCode as 'parObsSetCode',
c.ObsSetCode as 'chObsSetCode',
d.ObsItemCode as 'chObsItemCode',
r.RationaleID as 'RationaleLink',
a.RationaleFreeText as 'RationaleFreeText'
FROM $$DATABASE_NAME$$..txmr_TABLE1_chg a
INNER JOIN $$DATABASE_NAME$$..txmr_obs_set b ON a.parObsSetGUID = b.GUID
LEFT JOIN $$DATABASE_NAME$$..txmr_obs_set c ON a.chObsSetGUID = c.GUID
LEFT JOIN $$DATABASE_NAME$$..txmr_obs_item d ON a.chObsItemGUID = d.GUID
LEFT JOIN $$DATABASE_NAME$$..txmr_rationale r ON a.RationaleGUID = r.GUID
WHERE @StartDate <= a.DateModified AND @EndDate > a.DateModified
ORDER BY a.DateModified, b.ObsSetCode;
SELECT COUNT(*), 'exp_TABLE1_chg'
FROM LinkedDatabaseName...exp_TABLE1_chg;
The problem is that there are inconsistent usages of the $$DATABASE_NAME$$ substitution string. 问题是$$ DATABASE_NAME $$替换字符串的用法不一致。 In most cases it is used to reference a specific database
在大多数情况下,它用于引用特定数据库
$$DATABASE_NAME$$..txmr_TABLE1
but in the exec string: 但在exec字符串中:
EXEC $$DATABASE_NAME$$..dbo.txmr_ExtractPOCIS
there is one too many periods, which means that it is now referencing a different server and not a database. 有一个太多的句点,这意味着它现在引用不同的服务器而不是数据库。
Changing this statement to: 将此语句更改为:
EXEC $$DATABASE_NAME$$.dbo.txmr_ExtractPOCIS
should resolve the problem. 应该解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.