SQL Server and Microsoft.ACE.OLEDB.12.0 - sql-server

I am getting the following:
Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider did not give any information about the error. Msg 7303, Level 16, State 1, Line 1 Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
When I execute the following from a Stored Procedure in SQLServer -
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=c:\Users\v-bimoss\Source\Workspaces\External\Onesite\URLoadDB\Templates\T1-Current.xlsx', 'SELECT * FROM [Sheet1$]')
I have been through all the threads I could find on this topic - but still am having the problem
I have verified that:
The 64 bit Microsoft.ACE.OLEDB.12.0 drivers are loaded
Ad Hoc Distributed Queries is set to 1
Dynamic Parameter and Allow Inprocess are both set to 1
Changed MSSQL to run under my account
The account that is running MSSQL and the account I am using both have full access to C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp
Any help would be appreciated. -wmm

I had the same problem. After going through a number of answers installing the provider, dealing with the cryptic errors, I had a brief moment of joy when I didn't get an immediate error- instead the query never returned...
I finally got it working after wasting more than a day on it. The final fix was to change SQL Server to the Local System account to login.
Here's what I did:
Ensure Office and SQL Server have the same bit width (64-bit in my case).
Install ACE provider for 64-bit (Jet for 32-bit)
Configure server
USE [MSDB]
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE WITH OverRide
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE WITH OverRide
GO
USE [master]
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.16.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.16.0', N'DynamicParameters', 1
GO
Configure SQL logon. In SQL Server Configuration Manager
Open the server Properties -> Log On -> Log on as:
Change to Built-in account - Local System
Finally, here's my query:
SELECT * FROM OPENROWSET(
'Microsoft.ACE.OLEDB.16.0'
,'Excel 12.0;Database=C:\Temp\Test.xlsx;HDR=YES'
,'SELECT * FROM [Sheet1$]')

Sadly, OPENROWSET is know to be buggy for ACE. So there are a bunch of different things to try when trying to tweak it. Adding and removing a few of the following suggestions will hopefully do it for you:
1) xlsx files need to be called with Excel 12.0 Xml;
2) HDR=YES; Tells if a header record is present. It'll crash if there is and you have numerics. Change to NO if there is no header.
3) IMEX=1; This allows for mixed numeric and text fields. In case people start mixing letters in with your numerics.
4) There can be registry problems based on ACE 12.0 vs ACE 14.0. Double check your version.
5) Lastly, weirder than weird... OPENROWSET crashes when you have comments (or don't have comments). If you have --comment, by putting a space after the dashes, -- comment it sometimes helps. So if you have comments, try removing them or rearranging them and you may get a surprise. (I know... it's really a sad state of affairs.)
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;IMEX=1;Database=c:\Users\v-bimoss\Source\Workspaces\External\Onesite\URLoadDB\Templates\T1-Current.xlsx', 'SELECT * FROM [Sheet1$]')
Anyway, since OPENROWSET can be a bit unstable, you may want to import data using a different approach with staging tables, or csv files, etc. But if you get it working, it can be quite nice.
Hope that helps :)

I would check into the steps in these two but in particular checking and changing, if you can, the user who runs SQL Server:
Cannot create an instance of OLE DB provider Microsoft.Jet.OLEDB.4.0 for linked server null
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)"

Like you, I tried everything and I was near to despair when I discovered that the sheet in the excel file must have a name, and it must be referenced with a DOLLAR sign, like [mysheet$].
So here is my openrowset statement that finally works:
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.16.0', 'Excel 12.0;Database=\\svr\dir\myfile.xlsx;HDR=YES', 'SELECT * FROM [mysheet$]')
We are using SQL Server 2014 64-bit, using latest ACE provider (Version 16).

Related

SQL Server OPENROWSET without SYSADMIN role

We extensively use the OPENROWSET function to import .CSV and Excel files into our SQL Server 2012 environment, using MSDASQL or ACE:
SELECT *
FROM OPENROWSET ('MSDASQL',
'DRIVER={MICROSOFT access TEXT DRIVER (*.TXT, *.CSV)};',
'SELECT * FROM E:\INCOMING\REPORT_EXTRACT.CSV')
Or using ACE:
SELECT * FROM OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','TEXT;DATABASE=E:\INCOMING\;HDR=YES;', 'SELECT * FROM [REPORT_EXTRACT.CSV]');
We're experiencing the classic error message:
Msg 7415, Level 16, State 1, Line 1
Ad hoc access to OLE DB provider 'MSDASQL' has been denied. You must access this provider through a linked server.
The ONLY workaround to enable this, is granting said user(s) with the SYSADMIN role - obviously not ideal.
The location of the file(s) is on the server itself, for which the users accessing DO have the necessary permissions to access that file folder. The SQL Server service is running under the local system account with permission to interact with the desktop.
We've tried the following workarounds/fixes to no avail:
1 Executed the following code:
EXEC master . dbo. sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′ , N’AllowInProcess’ , 1
GO
EXEC master . dbo. sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′ , N’DynamicParameters’ , 1
GO
*2 The DisAllowAdHocAccess registry fix:
This is the current state:
3 Adding the ADMINISTER BULK OPERATIONS permission to the said users
We have dozens of expressions and files within our procedures that use OPENROWSET, therefore BULK INSERT, building SSIS packages, leverage Excel files as linked servers are NOT feasible options.
Any suggestions?
Wow - After YEARS of troubleshooting, I finally figured out what it was!
The registry entry value that controls the Allowing of Ad-hoc access, relies on the DisallowAdHocAccess being in that EXACT sentence case.
In our case, the "A" in AdHoc was not capitalized:
To fix this, I:
Deleted the registry value as described
Re-enabled the Disallow AdHoc Access option (Which re-created the registry value)
Manually set the Registry DisallowAdHocAccess value to "0"
Problem solved!

Cannot initialize the data source object of OLE DB provider Microsoft.ACE.OLEDB.12.0 for linked server (null)

DECLARE #PATH NVARCHAR(1000) = N'\\MY-SERVER\C$\Folder\\'
DECLARE #TABLE NVARCHAR(50) = SUBSTRING(#FILENAME,0,CHARINDEX('.',#FILENAME))
DECLARE #SQL NVARCHAR(4000) =
N'IF OBJECT_ID(''dbo.' + #TABLE + ''' , ''U'') IS NOT NULL
DROP TABLE dbo.[' + #TABLE + ']
SELECT * INTO [' + #TABLE + ']
FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0''
,''Text; Database='+#PATH+';''
,''SELECT * FROM [' + #FILENAME + ']'')'
EXEC(#SQL)
Today I have come across an issue with Microsoft.ACE.OLEDB.12.0 driver in SSIS 2012. The script above sits in a stored procedure which dynamically loads the .csv's into the database based on the current file which is supplied by the SSIS loop in which stored procedure sits. There are files in the directory.
The stored procedure runs correctly when run directly in SQL Server Management Studio.
This has been working fine up until today. Today I am getting the following error:
Executing the query "EXEC [dbo].[CreateAndImportCSVs] ?" failed with the following error: "Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".".
Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Any help on this issue would be great!
Edit
So looking into what's changed I hear alarm bells when I look at the windows updates installed on the server yesterday! The following two were installed:
Microsoft Office Access Runtime and Data Connectivity 2007 (SP3)
http://support.microsoft.com/kb/2526310
Update for the 2007 Microsoft Office System (KB967642)
http://www.microsoft.com/downloads/details.aspx?FamilyId=E93AB1BE-ADE6-4FF8-8637-DBD3EBE3C5C5&displaylang=en
Many things to Try:
Check the In Process and Dynamic Provider options for the ACE provider
Check the permissions on the Temp folder
Check the MemToLeave memory area allocated
Make sure the EXCEL process is not running in background
Made sure 'ad hoc distributed queries' was enabled (1)
USE [master]
GO
EXEC sp_configure 'Show Advanced Options', 1
RECONFIGURE
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE
GO
EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO
Read more at How to solve Microsoft.ACE.OLEDB.12.0 error "Unspecified error"
Also i found an interesting suggested solution in the following link, take a look:
The OLE DB provider Microsoft.Ace.OLEDB.12.0 for linked server (null)
This problem resolved itself. There were further updates installed, one of these must have fixed the issue introduced by the previous updates:
Update for Microsoft Office 2010 (KB4011188) 64-Bit Edition
https://support.microsoft.com/kb/4011188
Update for Microsoft Office 2010 (KB2553347) 64-Bit Edition
http://support.microsoft.com/kb/2553347
Security Update for Microsoft Office 2010 (KB2553338) 64-Bit Edition
https://support.microsoft.com/kb/2553338
Thanks for all the help with this!
The final piece that solved this for me was moving the spreadsheet to a windows directory that SQL Server was able to access. I moved my spreadsheet to a new subdirectory, within the directly where my sql database was located, and the problem was resolved.
SQL Server is not able to access the Access provider, if the installation of office was Click to Run installation.
The issue can be resolved by any of the following approaches.
OLEDB driver issues resolution
Resolution
Beginning with Microsoft 365 Apps for Enterprise Version 2009, work
has been completed to break ACE out of the C2R virtualization bubble
so that applications outside of Office are able to locate the ODBC,
OLEDB and DAO interfaces provided by the Access Database Engine within
the C2R installation.
Use the following table to understand if additional components are
necessary to access these intefaces within your environment:
Probably not a solution, but you should execute SQL with:
sp_executesql #SQL
It protects from injection and wotnot.

OPENROWSET with Excel file

I want to execute simple statement:
SELECT * FROM
OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Text;Database=C:\Temp\;','SELECT * FROM [test.csv]')
And suddenly I get this message today morning:
Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'MICROSOFT.JET.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
It was working till today morning!
Here is my server specs:
Windows 2008 R2 64 bit
SQL Server 2008 64 bit
I've installed AccessDatabaseEngine_x64.exe.
Sql Server is running under LocalService account.
I've set Everyone to have FullControl permission to "C:\Temp" as well as "C:\Windows\ServiceProfiles\LocalService\AppData\Local".
Is there anything I missed? I'm really confused...
Edited:
I've also executed these statements:
sp_configure ‘show advanced options’, 1;
GO
RECONFIGURE;
GO
sp_configure ‘Ad Hoc Distributed Queries’, 1;
GO
RECONFIGURE;
GO
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’AllowInProcess’, 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’DynamicParameters’, 1
GO
I've also tested ACE.OLEDB.12.0 with administrator account:
SELECT * FROM
OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','Text;Database=C:\Temp\;','SELECT * FROM [test.csv]')
There is another error:
OLE DB provider "MICROSOFT.ACE.OLEDB.12.0" for linked server "(null)" returned message "Unspecified error".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MICROSOFT.ACE.OLEDB.12.0" for linked server "(null)".
Finally I found it:
I ran ProcMon and I saw that Sql Server wants to access to F:\Windows Temp\ and the folder does not exist! I created the folder and the issue is solved. But, I never had such a folder!!!
Finally I found it: I ran ProcMon and I saw that SQL Server wants to access to F:\Windows Temp\ and the folder does not exist! I created the folder and the issue is solved. But, I never had such a folder!!!

How to query remote index catalogs

I've been trying to create a linked server in SQL Server that accesses a
remote Index Service catalog, but I can't seem to do it. Let's call
the remote server "remoteServer" and the Catalog "remoteCatalog"
I've tried this:
EXEC sp_addlinkedserver remoteIndexServer, 'Index Server', 'MSIDXS',
'query://remoteServer/remoteCatalog'
and then i did run the SQL
SELECT * FROM OPENQUERY(remoteIndexServer,'select filename from scope()') AS Q
But i got the error as
OLE DB provider "MSIDXS" for linked server "remoteIndexServer" returned message "Service is not running. ".
Msg 7320, Level 16, State 2, Line 3
Cannot execute the query "select filename from scope()" against OLE DB provider "MSIDXS" for linked server "remoteIndexServer".
I have experienced this issue before. This is from memory so excuse any errors but if I recall correctly you will need to do the following.
Install the indexing service on your local SQL Server (this is so the provider is available).
Add a linked server to this LOCAL indexing service.
You can then run you query as below
SELECT *
FROM OPENQUERY(
LocalLinkedServer,
'select filename from RemoteServer.CatalogName..scope()'
) AS Q
If that doesn't work let me know, there is a post somewhere that describes how to do this. I can look it up if necessary but I think the above is right.

Force addition/deletion of a linked server and correct syntax to import data into a table from Excel

I'm trying to create a linked server in Sql server 2008 R2, just tried downloading the '64-bit version of the Office 2010 Access AD Engine' exe from Microsoft.
Unfortunately, I had tried adding a linked server, BEFORE making this installation, and it failed:
EXEC sp_addlinkedserver 'LinkedServer1', 'Excel', 'Microsoft.Jet.OLEDB.4.0', 'D:\Folder\Excel1.xls', '', 'Excel 8.0', ''
(let me know if this way of adding is not correct if you have another way to do it !)
After making the download, it gave a message that this server already exists :
"There are still remote logins or linked logins for the server 'LinkedServer1'."
Tried adding 'LinkedServer2' in the same way AFTER the download (used Excel5.0 as the parameter instead of Excel8.0). It works!
However, this old linked server seems to still exist, though I've tried dropping it:
To be sure it's actually there, I wrote this:
select * from sys.servers where is_linked =1
and the properties in detail:
server_id: 1
name= LinkedServer1
product= Excel
provider = Microsoft.Jet.OLEDB.4.0
data_source= D:\Folder\Excel1.xls
location:NULL
provider_string: Excel 8.0
is_linked=1
is_data_access_enabled=1
modify_date= 2010-08-15 19:56:02.307
Let me know if you notice me doing something wrong! I tried dropping 'LinkedServer2', it works! However, even when I'm trying to drop the same linked server1 like this:
Exec sp_dropserver #server = 'LinkedServer1'
fails on me, same message!
"There are still remote logins or linked logins for the server 'LinkedServer1'."
Tried adding a linked server using provider string as 'Excel 5.0' and it was added and dropped successfully.
Another Update:
This is failing again:
EXEC(' INSERT INTO Table1
SELECT col1, excel2col, excel3col, Replace(Replace(excel4col, ''"'', '''')
FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 5.0;HDR=Yes;Database='+'D:\Folder\Excel1.xls'', [Sheet2$])')
Error:
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
I have changed configuration to :
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
Looks like a 64-bit/Sql Server R2 issue:
to delete a linked server explicitly , we should use:
sp_dropserver 'LinkedServer1', 'droplogins';
This solves the problem of an invalid linked server.
however, the Microsoft.jet.OLEDB.4 is not working, the same error keeps coming up:
<Errors> <Error>ERROR CAUGHT: OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.</Error> </Errors>
Tried downloading the Microsoft.ACE.OLEDB.12.0 and used this to add the linked server.
However, when I try to do an insert into table using OpenRowSet, a new error comes up:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. Access denied.
Msg 7301, Level 16, State 2, Line 1
Cannot obtain the required interface ("IID_IDBCreateCommand") from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Anyone faced this before, or knows how to solve this?

Resources