SqlClient Data Provider - Transaction error on Ad-Hoc Linked Servers...

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
I've noticed this error several times, and I'm trying to find not only the reason for such a glitch, but also the solution for it as well.

When creating ad-hoc queries (using the OPENROWSET() function in the sql server T-SQL language) it happens without fail that even though I can load up an excel file without a problem, when my application is finished processing the first file, unless I close my application and restart it, if I try to load a second Excel file, I get this error:
Cannot start a transaction for OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server (null)
Now linked server(null) simply means that it isn't a "statically" linked, linked server, but an ad-hoc linked for on-the-fly access to the excel table. However, I am rather confused as to why it would work the first time i run my application, but when I go to process the next document (workbook) it fails.

My order of operation is quite simple really:
  1. Application Start
  2. Database Login
  3. Create Connection String with Login Parameters (User/Pass or Integrated Security)
  4. Create Connection to Database.
  5. Load Dataset for viewing.
  6. Select file for processing.
  7. Free Dataset, Close Connection.
  8. Create new Connection
  9. Process Ad-Hoc Query and rules upon the Imported Data.
  10. Close Connection
  11. Create New Connection
  12. Load Dataset for viewing.

When I restart the process at stage 6, which basically is browsing for a new file and clicking a button on my form, I step through the process and it follows all the same patterns, clearing out the loaded dataset, closing the connection, creating a new connection, and it then attempts to load the Excel file but it doesn't load. I get the above error WITHOUT FAIL. Ideas? Suggestions? Please, I can deal for a moment with the necessity to shutdown and restart my app, but it should NOT have to do that just to create a stable connection to the database which allows ad-hoc processing.
Thanks
 
Back
Top