Problem with update sql with excel - sql-server-2005

I have a problem with this query:
UPDATE Provinces
SET Provinces.DefaultName=T2.Defaultname
FROM Provinces
INNER JOIN
OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\provinces.xlsx;HDR=YES',
'SELECT Code, Defaultname FROM [Arkusz1$]') T2
On Provinces.Code = t2.Code
WHERE Provinces.Code = T2.Code
I get error:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.Jet.OLEDB.4.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.Jet.OLEDB.4.0" for linked server "(null)".
What is the source of this error, and how can I modify the SQL statement?

There are several possible causes of this detailed here: Linked Server using Microsoft.Jet.OLEDB.4.0 problem.
A likely is cause is file system permissions of the temp directory for the sql service login for whoever is accessing that linked server: C:\Documents and Settings\(sql login name)\Local Settings\Temp

That is permission denied error. Follow:
How to import data from Excel to SQL Server
How to use Excel with SQL Server linked servers and distributed queries
Note If you are using SQL Server 2005, make sure that you have enabled the Ad Hoc Distributed Queries option by using SQL Server Surface Area Configuration.
sp_configure 'Ad Hoc Distributed Queries', 1

Related

sql opendatasource need to access files on a mapped network drive

I have a number of files in different formats (Excel, Access, and CSV) saved on a network drive and I need to use opendatasource and openrowset to insert the data into a SQL table. These queries will only work if the files are saved on the SQL server. Is there a way to get around this?
I have admin rights on my local machine and on the server with full read/write permissions. The drives are also mapped on the server. Here are the queries and the error messages that I am getting:
SELECT Seq, Label
FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Data Source = "G:\IMA Utilization Reports\\IMAv2k.mdb"' )...BackupLabels
Results in: OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "'G:\IMA Utilization Reports\DB\IMAv2k.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.".
SELECT Seq, Label
FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Data Source = "\\172.16.0.32\Finance\IMA Utilization Reports\DB\IMAv2k.mdb"' )...BackupLabels;
Results in: 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 '\172.16.0.32\Finance\IMA Utilization Reports\DB\IMAv2k.mdb'. It is already opened exclusively by another user, or you need permission to view and write its data.".
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'excel 12.0;HDR=yes;imex=1;driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; extended properties=excel 12.0 xml;
Database=G:\IMA Utilization Reports\Provider ID Numbers.xlsx',
'select * from [Employee ID Numbers$]')
Results in: Msg 7399, Level 16, State 1, Line 32
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 32
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
If anyone has an answer or can point me to somewhere that does I would greatly appreciate it. Thanks in advance.

Connect to SQL Azure DB using OpenRowSet from on-premise SQL Server

I am trying to connect to SQL Azure database from an on-premise SQL Server using openrowset, but it is failing with an error.
My query is
SELECT a.*
FROM OPENROWSET('SQLNCLI', 'Server=sqlazureserver.database.windows.net;Database=dbname;User ID=username;Password=password;Connection Timeout=30;', 'select * from [dbo].[tablename]') AS a;
and the error I get:
Msg 7399, Level 16, State 1, Line 11
The OLE DB provider "SQLNCLI11" for linked server "(null)" reported an error. Authentication failed.
Msg 7303, Level 16, State 1, Line 11
Cannot initialize the data source object of OLE DB provider "SQLNCLI11" for linked server "(null)".
I am able to successfully connect using linked server, but I do not want to go that route as my connection strings will be dynamic.
From documentation ,I could see open row set is not supported against SQL Azure database as of now.
Instead of openrowset,you can use distributed queries to accomplish the same
exec ('select * from table') at linkedserver

Execute remote SQL script with linked server

I've got 2 servers in a workgroup called "workgroup".
Server A is W2012R2 with SQL Server 2012.
Server B is W2012R2 with other application. SQLCMD Utility has been installed on server B.
I'm using local account, SQL service is start by local account. I can connect to the SQL server from B to A. I can launch query without difficulty. When I launch my SQL script, I get the following error:
E:\Batch\Script>sqlcmd -S YMSQL01 -i test.sql
Changed database context to 'PROD'.
Msg 7399, Level 16, State 1,
Server YMSQL01, Procedure V_C_Prod, Line 3 The OLE DB provider
"Microsoft.ACE.OLEDB.12.0" for linked server "C_PROD" reported an
error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Server YMSQL01, Procedure V_C_Prod, Line 3
Cannot initialize the data source object of OLE DB provider
"Microsoft.ACE.OLEDB .12.0" for linked server "C_PROD".
As you can see, it seems that I cannot query on a view. This view is from a linked server which is connected to an Excel file (located on server B). I have installed the same ODBC driver on server B but I get the same error.
My SQL script:
Use PROD
Go
Merge dbo.conc AS t
using V_C_Prod as s
ON (t.CodeComptable=s.[Code Comptable])
WHEN MATCHED THEN UPDATE SET
t.[Marque]=s.[Marque]
,t.[CodeHolding] = s.[Code HOLDING]
,t.[Email1]=s.[Email Principal]
,t.[CP]=s.[CP]
,t.[Ville]=s.[Ville]
WHEN NOT MATCHED
THEN INSERT VALUES (
s.[Marque]
,s.[Code HOLDING]
,s.[Code Comptable]
,s.[Email Principal]
,s.[CP]
,s.[Ville];
Go
How can I solve this issue?

Excel Linked Server in SQL Server 2008 R2 OLEDB error

I have set up a linked server from SQL Server 2008 R2 to an Excel spreadsheet, from which I read the contents in to a table, for comparison during an import.
The spreadsheet is held on a network share from an application server.
Basically, this works perfectly on the SQL Server when I run:
SELECT * FROM SpreadsheetLink...[CONTENTS$]
However, as I now need to schedule this, I need to create an SSIS package on the application server, which runs the same query.
So now, whenever I try to do this though (either by writing the script in to SSIS or by logging in to SQL Server Mgmt Studio on the App server and then opening an SQL connection to the SQL Server and querying directly) I get an error:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "SpreadsheetLink" 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 "SpreadsheetLink"
I first wondered whether I had forgotten to install OLEDB12.0 on the application server, but it is there.
I next wondered whether it was a permissions issue, so I added the EVERYONE group, with "Full Control" to the folder containing the spreadsheet and also ensured that the account that I am both logged in with and running the query as is an administrator on both the SQL server and the Application Server.
I also checked that the account was a member of the Distributed COM user group on both servers (it was).
Additional info:
I have tried several things, but it still fails.
I added the following
sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
I then re-tested, but got the same results (success from the local SQL server, failure from the other server).
Next, I tried creating a different query, referring to the spreadsheet directly by path, rather than by Link-name, but that resulted in exactly the same outcome:
SELECT * INTO TargetTableName FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=\\SERVER_NAME\PATH\fileName.xls;HDR=YES',
'SELECT * FROM [sheetName$]')
I also applied all of the suggestions in the following page:
http://visakhm.blogspot.co.uk/2013/12/how-to-solve-microsoftaceoledb120-error.html. But still no joy.

Update query SQL Server with Excel data

I'm trying to update my SQL table with an excel file.
When I try to use OLEDB, I get the error:
Server: 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.
I was trying the folowing query:
UPDATE x
SET x.ShopName = y.ShopName
FROM dbo.StandInStore x INNER JOIN
(
SELECT [Stand_ID], [ShopName]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;IMEX=1;Database=C:\Documents and Settings\vdbergv\Desktop\test.xls;', 'SELECT * FROM [Sheet1$]')) y
ON x.stand_ID = y.stand_ID
I have read/write wrights, but I think the server isn't supporting OLEDB, I'm not the administrator so I can't reconfigure the server, like many solutions on the internet.
Any idea how to solve this problem or an alternative for OLEDB?
Regards