Openrowset function failure - sql-server

I'm executing this openrowset function:
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\Users\JCPABALAN\Desktop\Data Migration\ListOfDiscards.xlsx;HDR=YES',
'SELECT * FROM [Sheet1$]')
But it gave me the following error
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Sheet1$' is not a local object, check your network connection or contact the server administrator.".
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
I have already set the Ad Hoc Distributed Queries into 1 and I Installed Microsoft ACE and also executed this line of 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
But it still won't work.

You Error message has two parts :
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Sheet1$' is not a local object, check your network connection or contact the server administrator.".
And
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
That the second part is because of error of first part, So your main error is at first part, that tells us:
The Microsoft Access database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly. If 'Sheet1$' is not a local object, check your network connection or contact the server administrator.
Some common causes and solutions are these:
Path not exists : File or Path C:\Users\JCPABALAN\Desktop\Data Migration\ListOfDiscards.xlsx is not exist;
Note : SQL Server C:\ is referring to the \\Server\C$, So if you are using SSMS and you register a Server and are connecting to it, your path is not exist.
File permission is denied : File or Path C:\Users\JCPABALAN\Desktop\Data Migration\ListOfDiscards.xlsx have security level that you can access them from SQL Server service account, You can grant access to SQL Server service account.
Sheet Name is invalid : Worksheet Sheet1 is not a valid sheet name in your workbook sheets, You maybe change its name.

Related

sp_rda_reauthorize_db not creating remote database copy

I have a db which is stretch enabled in SQL server 2016 RC3.
I took local backup of that database, and restored successfully. As we know that after restore the link to Azure SQL Server will get break, therefore I am using the below mention T-SQL to resume the connectivity, additionally I am specifying #with_copy = 1, so that it create a copy of database in Azure SQL server. But below mention T-SQL always fails with error as
Copying remote database 'RDADB_A40A50B5B-386A-42C4-B19C-3C2516172CAF' to remote database 'RDADB_A_Clone74FF1F31-A689-4866-BDD1-F90D15C157BB'.
OLE DB provider "SQLNCLI11" for linked server "stretchserver-sc-server-dbstrech-20160314-114758814.database.windows.net" returned message "Query timeout expired".
Msg 7399, Level 16, State 1, Procedure sp_rda_reauthorize_db, Line 1 [Batch Start Line 5]
The OLE DB provider "SQLNCLI11" for linked server "stretchserver-sc-server-dbstrech-20160314-114758814.database.windows.net" reported an error. Execution terminated by the provider because a resource limit was reached.
Msg 7320, Level 16, State 2, Procedure sp_rda_reauthorize_db, Line 1 [Batch Start Line 5]
Cannot execute the query "CREATE DATABASE [RDADB_A_Clone74FF1F31-A689-4866-BDD1-F90D15C157BB] AS COPY OF [RDADB_A40A50B5B-386A-42C4-B19C-3C2516172CAF]" against OLE DB provider "SQLNCLI11" for linked server "stretchserver-sc-server-dbstrech-20160314-114758814.database.windows.net".
CREATE DATABASE SCOPED CREDENTIAL AzureCred WITH IDENTITY = 'AzureAdministrator',
SECRET = '****' Declare #credentialName nvarchar(128);
SET #credentialName = N'AzureCred';
EXEC sp_rda_reauthorize_db #credential = #credentialName, #with_copy = 1
Note :- I have configured the firewall of Azure SQL server to include my IP.
The create copy part is a regression. I believe the fix is still being worked on. Please file a bug on https://connect.microsoft.com/SQLServer/feedback/ if you want to track its progress. In the meantime, you can set the option to 0 or false to avoid creating a copy. If you do need to make copies, let us know what your scenario is and we'll see if we can find you temporary workarounds.

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.

Unable to access CSV file using linked server using any login other than 'sa' [duplicate]

This question already has an answer here:
SQL Server Linked Server to Microsoft Access
(1 answer)
Closed 2 years ago.
I've set up a linked server to read a set of CSV files located locally on the SQL Server machine, as follows:
USE master
go
IF EXISTS (SELECT * FROM sys.servers WHERE name = 'MyLink')
EXEC sp_dropserver 'MyLink', 'droplogins';
EXEC sp_AddLinkedServer #server = 'MyLink',
#srvproduct = '',
#provider = 'Microsoft.ACE.OLEDB.12.0',
#datasrc = 'C:\Data\Feeds',
#provstr = 'Text'
EXEC sp_AddLinkedSrvLogin MyLink, FALSE
go
The following code then works perfectly, provided I'm logged in as 'sa' (either syntax works):
SELECT * FROM MyLink...myFile#csv
SELECT * FROM OPENQUERY(MyLink,'select * from myFile.csv')
If I log in as any other user, however, I get the following error:
Msg 7416, Level 16, State 2, Line 1
Access to the remote server is denied because no login-mapping exists.
Trying to change the remote login, either via script, or by modifying the linked server properties in SSMS to add a mapping, not only doesn't work but also breaks the ability of 'sa' to run the select statements.
BTW, I'm trying to work around a known bug in SSIS where it cannot handle CSV with commas inside double-quote-delimited fields. I stumbled across this post which describes using a linked server to get around the problem without having to code a custom parsing routine. Works great, except for the whole security thing; I don't want my application connecting as 'sa'. I'm using SQL 2005 SP3.
Any ideas on getting this to work with a run-of-the-mill login?
TIA,
Jim
#JustinStolle When I set it up as you describe, I get a different error for the non-sa user (sa still seems to work):
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "MyLink" returned message "Cannot start your application. The workgroup information file is missing or opened exclusively by another user.".
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "MyLink" reported an error. Authentication failed.
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 "MyLink".
I can't import the file; SSIS can't handle it.
Just from doing a little testing, it seems only users in the sysadmin role can query this type of linked server since it needs permissions to work with the file system. There is probably a more thorough explanation elsewhere of which exact permissions are needed.
It seems to work when, within the linked server's security settings, I map a user with no special permissions to the local sa user or another sysadmin user (despite it being labeled "Remote User").
For a long-term solution, why not create a job that imports the CSV file to a local table? It would make maintaining permissions simpler and you'd have a defined table structure against which to write queries.

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