title: Could not find server ‘DATABASE_NAME′ in sys.servers error
body: <p>The code below is embedded in a .sql file in a vb.net project. It gives me an error:</p>
  
  <p><strong>Could not find server ‘DATABASE_NAME′ in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.</strong></p>
  
  <p>I checked in sys.server and the LinkedDatabaseName is returned if i do a <strong>select * from sys.servers</strong></p>
  
  <p>Here is the code where I get the error....</p>
  
  <pre><code>-----------------------------------
  -- 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 &lt;= a.DateModified AND @EndDate &gt; a.DateModified
  ORDER BY a.DateModified, b.ObsSetCode;
  
  SELECT COUNT(*), 'exp_TABLE1_chg' 
  FROM LinkedDatabaseName...exp_TABLE1_chg;
  </code></pre>