title: Batch file that runs sql script getting error Ad hoc access to OLE DB provider 'Microsoft.ACE.OLEDB.12.0' has been denied.'
body: <p>'You must access this provider through a linked server.'</p>
  
  <p>I'm running this batch file remotely from the database server which is also remote. I'm trying to do an export which shouldn't have a need for the linked server.  When I run the query in SSMS it exports fine, but when it's executed from the batch, it gives me the error message below.  I think it may be because theyre on 2 different accounts.</p>
  
  <p>Here's my batch code:</p>
  
  <pre><code>SQLCMD -S dbserver -E -d dbname-i \\Network\fldr\rpt\test\script.sql
  PAUSE
  </code></pre>
  
  <p>Here is my SQL script:</p>
  
  <pre><code>SET ANSI_NULLS ON 
  GO
  SET ANSI_WARNINGS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  PRINT 'exporting data...'
  
  INSERT INTO OPENROWSET(
  'Microsoft.ACE.OLEDB.12.0', 
  'Excel 12.0;
  Database=\\Network\fldr\rpt\test\testdata.xls;', 
  'SELECT * FROM [Sheet1$]') SELECT * FROM [dbo].view_test ORDER BY [Col4]
  </code></pre>
  
  <p>Error message in cmd:</p>
  
  <p><img src="https://i.stack.imgur.com/AmxCZ.jpg" alt="enter image description here"></p>