Failed to get data from MS Access - sql-server

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.

Related

Import data from XLS file to SQL Server 2008 R2 database

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'?

Export SQL QueryResult to Excell file on Server without installing Office

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).

How can I setup my SQL Server LocalDB to be as close to a normal SQL Server?

SQL Server LocalDb does not support "sa" login out of the box.
It also does not like connections from other users nor it stays up enough.
So I need a way to enable most of the normal and expected functionality of a normal SQL Server on a LocalDB server.
Create a shared instance of the Local db
SqlLocalDB.exe create "DeptLocalDB"
SqlLocalDB.exe share "DeptLocalDB" "DeptSharedLocalDB"
SqlLocalDB.exe start "DeptLocalDB"
SqlLocalDB.exe info "DeptLocalDB"
The last command will give you the pipename.
Create an sql alias to that pipe name, open C:\WINDOWS\system32\cliconfg.exe and create it in the alias tab.
If using x64 also add the alias at Start > Sql Server Configuration Manager > Sql Native Client. I had to install Sql Server Shared Features to get that option in Start Menu.
https://download.microsoft.com/download/7/f/8/7f8a9c43-8c8a-4f7c-9f92-83c18d96b681/SQL2019-SSEI-Expr.exe
BONUS: If you name your alias localhost now you have almost the same as SQL Express.
Connect to that alias using windows authentication and
sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'user instance timeout', 30;
GO
To configure the sa password do:
ALTER LOGIN sa ENABLE ;
GO
ALTER LOGIN sa WITH PASSWORD = '<enterStrongPasswordHere>' ;
GO
If you need a SQL Server instance that works just like a regular one, you can install SQL Server Express. LocalDB was specifically intended to be more lightweight and easier to administer than Express, but if you need a server that runs continuously, you're better off with Express.

SQL Server 2012 - Openrowset - User without sysadmin

Environment :
Server : Windows Server 2012
SQL Server : SQL Server 2012
I want to use openrowset in my production environment without granting sysadmin to the user. saw a lot of posts about this issue but non seem to provide a solution to mine.
I performed the following steps:
Created a non administrator windows account
Created a windows authentication login in my database (not sysadmin)
Enabled 'show advanced options','ad hoc distributed queries'
Verified 'Disallow adhoc access' is disabled in the provider (key does not exist in the registry)
Enabled driver
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
Changed the user running the SQL server service to be Administraor
Granted full permissions on the TEMP , TMP directory of the Administrator to the user created on Step1.
Whenever I run the query:
SELECT *
FROM OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','Excel 8.0;Database=c:\temp\xxx.xls;','SELECT * FROM [xxx$]')
I get:
Ad hoc access to OLE DB provider 'MICROSOFT.ACE.OLEDB.12.0' has been denied. You must access this provider through a linked server.
It does not seem to even try to access the file because whether it is there or not I get the same error. When I run it with the sysadmin user it works and when I try to query a non existing file I get error it can't find it in oppose to the non sysadmin user.
Maybe I am missing a permission on different directory or the the non sysadmin user is missing other permission.
Can you please advise?
Thanks
Doron

SQL Server 2012 querying Access 2007 data using OPENROWSET error

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.

Resources