title: Close excel file after reading with ODBC driver using VBScript
body: <p>I have an excel file that is being read with using ODBC driver with the following code:</p>
  
  <pre><code> filePath = "folder\myExcelFile.xlsx"
  
   odbcPath = "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=YES; "&amp;_
  "Excel 8.0; DBQ=" &amp; Server.MapPath(filePath) &amp; ";"    
  
  'xlsx driver 2007+
  if InStr( lcase(filePath),".xlsx" ) &gt; 0  then
      odbcPath= "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; "&amp;_
      "DBQ=" &amp; Server.MapPath(filePath) &amp; ";"        
  end if  
  
  'Excel processing
  Dim objConn
  Dim objRs  
  
  set objConn = Server.CreateObject("ADODB.Connection")
  set objRs = Server.CreateObject("ADODB.Recordset")
  
  objConn.Open odbcPath 
  
  strSQL = "SELECT * FROM A1:Q50000"
  
  objRs.LockType = 1
  set objRs = objConn.Execute(strSQL)    
  
  Do Until objRs.EOF
      ''Do stuff
       myfield = objRs.Fields("fieldName")
       ''...other code...
  Loop
  
  objRs.Close
  objRs.ActiveConnection = Nothing
  set objRs = Nothing
  
  objConn.Close     
  set objConn = Nothing
  </code></pre>
  
  <p>Inmediately after this, when I attempt to delete the file with the following:</p>
  
  <pre><code>Dim objFSO_Del
  Set objFSO_Del = CreateObject("Scripting.FileSystemObject")
  
  objFSO_Del.DeleteFile Server.MapPath(filePath), True
  </code></pre>
  
  <p>I get a <code>permission denied</code> error, which shouldn't happen because my IUSR account has all the privileges (total control) to the folder where this action takes place. In fact when I comment the code posted above and attempt to delete the file, the operation is successful</p>
  
  <p>I was thinking on fetching the excel records using:</p>
  
  <pre><code>set objExcel = CreateObject("Excel.Application")
  set objWorkbook = objExcel.Workbooks.Open(Server.MapPath(filePath))
  </code></pre>
  
  <p>As this would allow me to have precise control to close the file and quit the Excel process.</p>
  
  <p>Is there a way I can release and delete the excel file efficiently using the ODBC technique?. I've done a fair amount of research and haven't found a solution for now.   </p>
  
  <p>Thank you very much for the insight.</p>
  
  <p>****Update**** </p>
  
  <p>I tested my original code again and it actually works on xls but not on xlsx files.</p>
  
  <p>When I use ACE.OLEDB engine as suggested by <a href="https://stackoverflow.com/users/69820/oracle-certified-professional">oracle certified professional</a>, I get no permission denied errors:</p>
  
  <pre><code>odbcPath = "Provider=Microsoft.ACE.OLEDB.12.0;" &amp;_
  "Data Source=""" &amp; Server.MapPath(filePath) &amp; """;" &amp;_
  "Extended Properties=Excel 8.0;"    
  </code></pre>
  
  <p>However I think should be a way to do this using the original engine to make this work on xlsx files.</p>