I have a service I wrote that uses a filewatcher. On create it takes the excel file and truncates table and import it.
It works on my Windows 7 box. When I drag a new file into the folder it imports it. If i drag a newer file it deletes the old data and imports the new data.
On Windows 2012 Server the service works on the first import. on the second drop of a excel file (second time the service tries to import) I get
Error during import of file 20151106.xls
Exception occured in Microsoft JET Database Engine
Exception: The Microsoft Jet database engine cannot open the file. It is already opened exclusively by another user, or you need permission to view its data.
This shouldn't happen as I close the connections
private void copy_excel(string FullPath)
string cmdText = "SELECT [ID], [NAME], [PRODID], [FTDATE]"
" FROM [DAILY$]";
string excelConnString = "provider=microsoft.jet.oledb.4.0;" +
" Data Source=" + FullPath + " ;Extended Properties=" +
using (OleDbConnection oleDbConn = new OleDbConnection(excelConnString))
using (OleDbCommand oleDbCmd = new OleDbCommand(cmdText, oleDbConn))
using (OleDbDataReader dr = oleDbCmd.ExecuteReader())
DataTable dt = new DataTable();
The service works fine on my windows 7 box and works for the first file on Windows 2012 server. Why is the service leaving the connection oleDbConn open on Windows Enterprise Server 2012? ?