I want write result rows of a query to a excell file:
INSERT into OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\temp\testing.xlsx;',
'SELECT Id,CompanyName FROM [Sheet1$]')
select Id,CompanyName from tbl_Company
But When Running This query following error occurs :
Msg 7302, Level 16, State 1, Line 3
Cannot create an instance of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
What is done before running this code :
1 - I installed "2007 Office System Driver: Data Connectivity Components"
2 - Executed Configuration Script for using excell :
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
3 - Change Login Account for SQL Server Service to local account
4 - Added Full Access permission on Excell file folder to local account
5 - Restarted SQL Service
But my problem remains
Server : Windows Server 2008
MS Office not installed on server
SQL Server 2014 64bit SP1
I had a mistake :
I should run this configuration script
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
also you should be sure to install 64bit version of Access Database Engine (if your sql server is 64bit).
Related
I am trying to import an Excel file into SQL Server for that I decided to use
OPENROWSET.
I have done below steps:
Step 1:-
sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
Step2:-
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
Step3:-
Installed AccessDatabaseEngine_X64.Exe file.
Step4:-
SELECT* FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=D:\Share\c.xls;',
'SELECT * FROM [Sheet1$]')
Here I got ERROR like this
"The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered."
But above all the steps executed without any error.
When I run this below query
Exec sp_MSset_oledb_prop
I can't find "Microsoft.ACE.OLEDB.12.0" in the list.
Server Configuration blow:
OS: Windows Server 2016 - 64bit
SQL: Sql Server 2017
The same way I have followed the above Steps working fine 2 different servers.
Kindly help me to resolve this issue.
I'm using a PC with Windows 10 64bit as OS, Visual Studio 2012, SQL Server 2012 64bit, Microsoft Office 2016. I'm running this script to get data from MS Access file
SELECT DISTINCT UserId,CheckTime
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','D:\att2000.mdb';'admin';'',CheckInOut)
Before I run that script, I've installed Microsoft Database Engine 2016 then run a few scripts
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
and this
USE [master]
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
Then I set the msqlserver service account to local account, after that I can get data from MS Access. But sometimes I get this error
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.)
I cannot connect to database engine and have to restart SQL Server, I can run query to other tables in SQL Server as usual but for that particular
script to get data from MS Access, it fails and I got that error. Then I noticed that 'SQL Server Configuration Manager' disappeared from program list.
I tried to search but can't find it.
Add SQL Server Configuration Server as below:
1 - Start —> Run —> mmc.exe
2 - In Menu Bar —> File —> Add/Remove Snap-in (or CTRL + M)
3 - Add SQL Server Configuration Manager and click OK
Try to restart the services and let me know if the problem persist.
I have data stored in Microsoft Azure and want to retrieve and store into Microsoft sql server 2008 r2
without creating linked server.
Try:
Step 1: Configured Firewall settings in Azure by adding Client IP.
Step 2: Running following query from SQL Server:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
SELECT *
FROM OPENROWSET('MSDASQL', 'Driver={SQL SERVER}; Server=server.database.windows.net;Database=DBName;UID=Admin; PWD=********;', 'select * from tablename')
Note: The above steps works fine but after sometime getting following error:
Cannot initialize the data source object of OLE DB provider "MSDASQL"
for linked server "(null)".
The "SQL Server" ODBC driver that ships with Windows is deprecated and cannot be used with Azure SQL Database. It's generally best to use OLE DB with linked servers instead of ODBC when possible.
Below is and example using a SQL Server Native Client OLE DB driver:
SELECT *
FROM OPENROWSET('SQLNCLI', 'Server=server.database.windows.net;Database=DBName;UID=Admin;PWD=********, 'select * from tablename;')
Here's our situation:
We have:
SI = 64bit Windows Server 2008 R2 Standard
DB = SQL Server 2008 R2
NO Microsoft Office package are installed on this server (we can't open .xls, .ppt, .doc etc)
We tried to import an Excel 97-2003 file using the wizard and everything worked!
The problem is: we need to execute a query with some control in it that imports data from the Excel file into our database.
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\file.xls', 'SELECT * FROM [Clienti$]')
but we get the following error:
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.
We already configured some options following this guide
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
Unfortunatly according to this thread:
Microsoft.Jet.OLEDB.4.0 is not supported for 64-bit OS.
Additionally this link may be helpful to work through.
Try change 'Microsoft.Jet.OLEDB.4.0' to 'Microsoft.ACE.OLEDB.12.0'?
I would like to query data in Management Studio from a Microsoft Access 2007 database located on the same machine as my SQL Server 2012 instance. I do NOT want to use a linked server to do this as different Access databases can be chosen by the user. I am following the directions found on technet and other sources I have read said to use OPENROWSET as the proper way to do what I want, but when I execute this in Management Studio...
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'C:\Users\oliver.klosoff\Desktop\New folder\41000-13-0085 Consolidated Killers LLC.mdb';
'admin';'',tblTtlHrsFringes);
...I get the error below:
Msg 7302, Level 16, State 1, Line 1
Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
The database does not have a password set for the admin user, and the admin user has permissions to read this table. Access 2007 32bit is installed on the machine, which is 64 bit, as well as the SQL Server instance. I believe that SQL Server can access the database file because when I get 1 when I execute this:
DECLARE #out INT
EXEC master.dbo.xp_fileexist 'C:\Users\oliver.klosoff\Desktop\New folder\41000-13-0085 Consolidated Killers LLC.mdb', #out OUTPUT
SELECT #out`
Is there a way to do what I am trying to accomplish?
Finally, after several unsuccessful attempts to have SQL Server "talk to" an Access database – either as a "Linked Server" in SSMS or via OPENROWSET() in T-SQL – I found this blog post that offered the following three (3) suggestions.
Tweak #1: OLE DB Provider settings
The OLE DB Provider for ACE (or Jet) must have the "Dynamic parameter" and "Allow inprocess" options enabled. In SSMS, open the
Server Objects > Linked Servers >Providers
branch, right-click "Microsoft.ACE.OLEDB.12.0" (or "Microsoft.Jet.OLEDB.4.0"), choose "Properties", and ensure that those options are selected:
Tweak #2: Temp folder permissions
This is the one that was stumping me.
Apparently SQL Server needs to write information into a temporary file while running an OLE DB query against an Access database. Because SQL Server is running as a service it uses the %TEMP% folder of the account under which the service is running.
If the SQL Server service is running under the built-in "Network Service" account then the temp folder is
%SystemRoot%\ServiceProfiles\NetworkService\AppData\Local\Temp
and if it is running under the built-in "Local Service" account then the temp folder is
%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Temp
My problem was that SSMS was running under my account (not NETWORK SERVICE) so I only had Read access to the Temp folder
Once I granted myself Modify permissions on that folder
and enabled OPENROWSET queries as documented in another question here, namely ...
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
... my query worked fine:
Tweak #3: memory_to_reserve
Although I didn't need to use it in my case, the aforementioned blog also claims that adjusting the "-g memory_to_reserve" startup parameter for the SQL Server service can also help avoid similar errors. To do that:
launch SQL Server Configuration Manager
right-click the SQL Server service ("SQL Server Services" tab) and choose "Properties"
on the "Advanced" tab, prepend -g512; to the "Startup Parameters" setting
restart the SQL Server service
For more details on the "memory_to_reserve" setting see the MSDN article here.
This should work
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
USE [DatabaseName]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SELECT * FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0','Data Source="C:\Employees.accdb"')...tblEMPS;
Assuming you have the 'Northwind' sample installed (and in folder mentioned below), will the following run?
SELECT CustomerID, CompanyName
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb';
'admin';'',Customers);
GO
Unfortunately I have not reinstalled SQL Server since my last reimage
Microsoft.Jet.OLEDB.4.0 may not work now(in 2018). Need to download AccessDatabaseEngine_X64.exe or AccessDatabaseEngine.exe to SQL server and intall it. Then use Microsoft.ACE.OLEDB.12.0.