Openrowset password protected excel file - sql-server

I am getting the below error message and am trying to find the correct syntax to specify the user id/password to connect to the excel file. Can you help with how this should be input?
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "The Microsoft Access database engine cannot open or write to the file ''.
It is already opened exclusively by another user, or you need permission to view and write its data.".
Msg 7303, Level 16, State 1, Line 58
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
SELECT *
FROM OPENROWSET(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;
Database=filename;
HDR=YES;',
'SELECT * FROM sheetname')

Related

Dynamic SQL Error -104 from Linked Firebird Database

I have a SQL Server database and a Firebird database as a linked server. I'm trying to select a table in the linked server, but I get the following error:
OLE DB provider "MSDASQL" for linked server "FIREBIRD" returned message "[ODBC Firebird Driver][Firebird]Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 22
.".
Msg 7306, Level 16, State 2, Line 4
Cannot open the table ""de_ib"."ROHSTOFF"" from OLE DB provider "MSDASQL" for linked server "FIREBIRD".
I have synonyms for the linked tables set up in my SQL database. The following three statements all return this error:
SELECT * FROM ROHSTOFF
SELECT * FROM [dbo].[ROHSTOFF]
SELECT * FROM [FIREBIRD].[de_ib]..[ROHSTOFF]
But the following returns the data as expected:
SELECT * FROM OPENQUERY(FIREBIRD, 'SELECT * FROM ROHSTOFF')
If I right-click a linked table and select Script Table as > INSERT To > New Query Editor Window, the following appears in the query editor:
-- [FIREBIRD].[de_ib]..[ROHSTOFF] contains no columns that can be selected or the current user does not have permissions on that object.
I'm logged in with credentials that match the owner of the Firebird database.
Why am I getting this error and how can I select data from my linked server without using OPENQUERY? I have a legacy application that selects from the Firebird database, but I need it to select seamlessly from the synonyms instead.

Openrowset function failure

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.

SQL Server 2008 - Linked Firebird Server - not working properly

I have a SQL Server 2008. I have created an ODBC connection to a Firebird database using the Firebird/InterBase(r) driver.
The connection works ok.
Then I created a linked server in SQL Server 2008 using the Microsoft OLE DB Provider for ODBC diver.
Everything seems to work fine. I can pull data from tables using
SELECT * FROM OPENQUERY(LINKEDSERVERNAME, 'SELECT * FROM TABLENAME')
with success.
My problem is remote store procedure call. On the Firebird side there is a stored procedure that has one input parameter. Sometimes I get the result, but most of the time I get an error. I am not sure why it is happening, but I don't understand much from the error.
I call the procedure like this:
SELECT * FROM OPENQUERY(LINKEDSERVERNAME, 'SELECT * FROM GET_DOCUMENT_S(05011002766916)'
Its either I get the result (1 row) or I get an error. For id 05011002766916i always get the result, but for some id I never get an result, even tho the Firebird admin claims that the same procedure call returns result normally on his client.
Here are the errors I am getting:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "LINKEDSERVERNAME" reported an error. The provider did not give any information about the error.
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT * FROM GET_DOCUMENT_S(04170200133A120)" for execution against OLE DB provider
"MSDASQL" for linked server "LINKEDSERVERNAME".
Or:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "LINKEDSERVERNAME" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LINKEDSERVERNAME".
Can someone please explain what could be the issue, as currently I dont know if its a problem in ODBC, linked server or Firebird side...
Thank you.
The problem was on Firebird side. I used Flamerobin client and it produced IBPP:SQLException

Querying an Oracle database from SQL Server

I have an Oracle 11g XE database that I would like to transfer into SQL Server Express 2005.
At first I thought I'd just generate the tables in Oracle as SQL, manipulate the data formats, and run the query in SQL Server. This worked for small tables, but I have several tables with a few hundred thousands rows and some with millions of rows, so this solution won't work.
I then created a TNS file with the following content:
OracleTnsName =
(
DESCRIPTION=
(
ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT=1521)
)
(
CONNECT_DATA = (SERVICE_NAME=XE)
)
)
I followed instructions I found elsewhere on how to generate the ODBC connection, and the 'test connection' was successful.
I then ran these commands to create a Linked Server in MS SQL:
EXEC sp_addlinkedserver
#server = 'OracleLinkServer'
,#srvproduct = 'OracleTnsName'
,#provider = 'MSDASQL'
,#datasrc = 'OracleTnsName'
EXEC sp_addlinkedsrvlogin
#rmtsrvname = 'OracleLinkServer'
,#useself = 'False'
,#locallogin = NULL
,#rmtuser = 'user'
,#rmtpassword = 'password'
Now I'm trying to query a table in the Oracle database from SQL Server using openquery:
select * from openquery(OracleLinkServer, 'select * from oracleTable')
But get an error:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for
linked server "OracleLinkServer" 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
"MSDASQL" for linked server "OracleLinkServer".
When I check the properties of the Linked Server, and just click the OK, I get this error:
TITLE: Microsoft SQL Server Management Studio Express
"The linked server has been updated but failed a connection test. Do you want to edit the linked server properties?"
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)
The OLE DB provider "MSDASQL" for linked server "OracleLinkServer" reported an error. The provider did not give any information about the error.
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "OracleLinkServer". (Microsoft SQL Server, Error: 7399)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.5000&EvtSrc=MSSQLServer&EvtID=7399&LinkId=20476
BUTTONS:
&Yes
&No
Please help!
Thanks
If you have successfully added your linked server, you no longer need OPENQUERY. You can just include the linked server name as the first part of the qualified name like so:
SELECT * FROM OracleLinkServer.database.schema.table
Not sure which parts you need, but the dots are key. Try this first:
SELECT * FROM OracleLinkServer...oracleTable
select *
from [server]..[xxx].[yyyyy]
It works for me.
Change
,#provider = 'MSDASQL'
with
,#provider = 'MSDAORA'

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