title: SQL: Check existence of a file on local machine when i'm connected to another database server
body: <p>I have two test Machines. i don't know if this is possible but here is what im trying to do</p>
  
  <ol>
  <li><p>Machine1: has DBServer setup</p>
  
  <p>where i am currently logged in</p>
  
  <p>where the file C:\test_IDNumber1.txt is located</p>
  
  <p>where i use SSMS. i connect to Machine2\SQLServer</p></li>
  <li><p>Machine2: has DBServer setup</p>
  
  <p>where the dbserver for DBTest is located</p>
  
  <p>DBTest is where the Filename records are stored</p></li>
  <li><p>First i need to do some select script from DBTest to get the IDNumber for the Filename</p>
  
  <pre><code>SELECT FileName FROM tblFiles where...... (results to "IDNumber1")
  </code></pre></li>
  <li><p>Then i'll check the existence of the file with the same IDNumber (e.g: "C:\test_IDNumber1.txt") using this script</p>
  
  <pre><code>EXEC xp_fileexist 'C:\test_IDNumber1.txt', @exists OUTPUT
  </code></pre></li>
  <li><p>If the file exists, i need to delete the record from DBtest on Machine2 and the file from Machine1</p>
  
  <pre><code>DELETE FROM tblFiles where Filename = 'IDNumber1'
  EXEC master.dbo.xp_cmdshell 'del ''C:\test_IDNumber1.txt'''
  </code></pre></li>
  </ol>
  
  <p>but the result for existence is always 0 because it is checking the C drive of Machine2 where the DBTest is located.</p>
  
  <p>Is there a way to use a select script from a db from Machine2 and check the existence of a file from Machine1?</p>
  
  <p>thank you very much</p>