Cannot read Excel file from SQL Server with multiple versions of SQL Server - sql

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
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
Reading Excel
DECLARE #SQLconnect VARCHAR(8000)
SET #SQLconnect = 'SELECT * FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0'',
''Excel 8.0;Database=D:\WAGES.xlsx;'',
''SELECT * FROM [Sheet2$]'')'
EXEC (#SQLconnect)
Exception
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider reported an unexpected catastrophic failure.
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)".
Sometimes it gives error sometimes it goes in infinite loop of execution.
NOTE: I am getting this error after installing SQL Server 2008 R2 over SQL Server 2012.
OS: Windows 7 32-bit
SQL Server 2008 R2 and SQL Server 2012 installed

The SQL Server Error Message if a user have no rights for SQL Server TEMP directory:
OLE DB provider "Microsoft.Jet.OLEDB.4.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.Jet.OLEDB.4.0" for linked server "(null)".
Grant rigths to TEMP directory
(i.) This step is required only for 32-bit SQL Server with any OLE DB provider
The main problem is that an OLE DB provider creates a temporary file during the query in the SQL Server temp directory using credentials of a user who run the query.
The default directory for SQL Server is a default directory for SQL Server service account.
If SQL Server is run under Network Service account the temp directory is like:
C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp
If SQL Server is run under Local Service account the temp directory is like:
C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp
Microsoft recommends two ways for the solution:
A change of SQL Server TEMP directory and a grant of full rights for all users to this directory.
Grant of read/write rights to the current SQL Server TEMP directory.
See details: PRB: "Unspecified error" Error 7399 Using OPENROWSET Against Jet Database
Usually only few accounts are used for import operations. So we can just add rights for these accounts.
For example, icacls utility can be used for the rights setup:
icacls C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp /grant vs:(R,W)
For more information follow this Link

Try these settings
Open SQL Server Configuration Manager.
Select the SQL Server Services folder in the left pane.
Right-click the SQL Server (MSSQLSERVER) service in the right pane.
Click Properties.
Click the Advanced tab in the properties dialog that pops up.
Add “-g512;” to the front of the value for parameter “Startup Parameters”.
Click OK.

Related

How to access Database from other computer using sql query in sql server

I am using a SQL database residing on my local computer. I want to access a table from a database residing on another computer using SQL query.
I have been able to connect the remote database with my database and all its tables are shown in Enterprise manager on my local machine. I have added remote SQL Server in my local SQL Server.
When I use select statement in my local SQL server it gives the message database does not exist or access denied.
Any help in this would highly be appreciated.
EDITED
Select * from [ServerName].DatabaseName.dbo.tableName
Use OPENROWSET
Example
SELECT t.version FROM
OPENROWSET('SQLNCLI', 'server=Myserver;UID=xxxx;pwd=yyyy',
'select ##version version') t
Note:
SQLNCLI is the name of installed OLE DB provider
Datasource: {server=Myserver;UID=xxx;pwd=yyy}
You have to enable OPENROWSET by executing the following script:
sp_configure 'show advanced options', 1
reconfigure
go
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
OPENROWSET is like connecting to a linked server

SQL Server 2008 linked server connection string setup

I'm trying to setup a linked server to another instance of SQL Server installed on the same Windows Server. In the SQL Server Management Console I have both instances added and I'm trying to do a insert from one database into another. I setup the linked server using the query below and I'm getting the following failure message when I test the connection of the the linked server. Can someone help me solve this problem?
USE master
GO
-- To use named parameters:
EXEC sp_addlinkedserver
#server = 'Server Name', --actual server name
#srvproduct = '',
#provider = 'MSDASQL',
#provstr = 'DRIVER={SQL Server};SERVER=Database name;UID=test_user;PWD=test_pwd;'
GO
Error message
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "Server Name".
OLE DB provider "MSDASQL" for linked server "Server Name" returned message "[Microsoft] [ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).".
OLE DB provider "MSDASQL" for linked server "Server Name" returned message "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.". (.Net SqlClient Data Provider)
exec sp_addlinkedserver #server='servername';
exec sp_addlinkedsrvlogin #rmtsrvname='servername',#useself=false, #rmtuser='sa', #rmtpassword='Password';
if sql server is a named instance then servername\instancename

Openrowset on SQL Server 2008 R2 installed in Windows 2008 64 bit machine

I'm trying to working with Openrowset on SQL Server 2008 R2 installed in Windows 2008 64 bit machine.When I execute the below query, i got an error like below.Please help me out.
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=E:\01112012.xls;','SELECT * FROM [Sheet1$]')
ERROR:
Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered.
Have you installed: ->Microsoft Access Database Engine 2010 Redistributable
This download will install a set of components that facilitate the transfer of data between existing Microsoft Office files such as Microsoft Office Access 2010 (*.mdb and .accdb) files and Microsoft Office Excel 2010 (.xls, *.xlsx, and *.xlsb) files to other data sources such as Microsoft SQL Server. Connectivity to existing text files is also supported. ODBC and OLEDB drivers are installed for application developers to use in developing their applications with connectivity to Office file formats.
To run OPENROWSET in 64 bit version of windows.
1- Install AccessDatabaseEngine_x64.exe (Restart is required).
2- If you are using SQL Management Studio, run Management Studio as administrator. If you don’t run it as an administrator account you will have this error (Cannot initialize the data source object of OLE DB provider "MICROSOFT.ACE.OLEDB.12.0" for linked server "(null)".
3- Run this command to configure your Database
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE with override;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE with override;
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
4- Don’t use ‘select * from sheet1$’ in OPENROWSET function. Try this code.
select * from OPENROWSET('MICROSOFT.ACE.OLEDB.12.0', 'Excel 12.0;HDR=YES;DATABASE=D:\test.xlsx', sheet1$)
If still you have (32 bit) error, try to restart your SQL service and check your C:\Windows\Temp and see do you have access to this directory or not.

Advantage to SQL 2000 Linked Server Access Denied Error

I am trying to create linked servers in SQL Server 2000 and SQL Server 2005 x64 to a Sybase Advantage database using the Advantage OLE DB Provider, 32-bit and 64-bit respectively.
I kept getting the following error when trying to browse the catalog and when performing a query with openquery from both SQL Servers:
OLE DB error trace [OLE/DB Provider 'Advantage OLE DB Provider' IUnknown::QueryInterface returned 0x80070005: Access denied.].
Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'Advantage OLE DB Provider' reported an error. Access denied.
The following Stack Overflow question and answer helped me resolve this problem on SQL Server 2005 x64:
Advantage to SQL 2008 Linked Server Access Denied Error
However, I am still getting the access denied error in SQL Server 2000, despite setting Allow inprocess as suggested above.
Both linked servers use the same data source, login credentials and server options. Any help is greatly appreciated.
Try running a query in the Query Analyzer. You should see the Advantage specific OLE DB errors returned. For example:
Server: Msg 7399, Level 16, State 1,
Line 1 OLE DB provider 'Advantage OLE
DB Provider' reported an error.
[OLE/DB provider returned message:
Error 7078: The Advantage Database
Server cannot authenticate the user.
Make sure the user name and password
are correct. axServerConnect
AdsConnect]
In this case it was a bad user/password

Linked server issue while migrating shards from SQL Server 2005 to 2008 Enterprise R1

I am facing a strange problem during data migration. We "restored" data from 3 shards(on diff SQL Server 2005 machines) to single SQL Server 2008. We have single 2008 server now but the shards are unchanged from 2005.
Now I am trying to exec a SP on Master but I get the following error
Creating SP
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.".
Msg 53, Level 16, State 1, Line 0
Named Pipes Provider: Could not open a connection to SQL Server [53].
All shards are on SQL Server. We are not using SQLNCLI10 provider. But it's strange to see this error.
My SP use some dynamically created distributed queries in SP.
eg. Shard01.dbo.Update.....
What could possible go wrong.
Solved the problem.
My SP was using a view which was moved restored from 2005 to 2008. 2008 has different shards configurations and SQLNCLI10 was used for OPENROWSET in 2005 but not in 2008 as all the DBs were on same server.
Redefining the view solved the issue.