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

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

Related

"Query Cannot Be Updated because the FROM clause is not a simple single table name" Error

I have a linked server in MS SQL Server to an ODBC data source referencing DBF files. These files are not in a database so I am using the OPENQUERY() syntax to access the tables. the SELECT query works just fine. Here is the Syntax for that:
SELECT * FROM OPENQUERY(VTESTCORP, 'SELECT * FROM [VNAME]')
But then when I try to append to one field in the table, I get this error
OLE DB provider "MSDASQL" for linked server "VTESTCORP" returned message "Query cannot be updated because the FROM clause is not a single simple table name.".
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "VTESTCORP" reported an error. The provider reported
an unexpected catastrophic failure.
Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "MSDASQL" for linked server "VTESTCORP" could not INSERT INTO table "[MSDASQL]".
Here is the append OPENQUERY () query I am using:
INSERT OPENQUERY (VTESTCORP, 'SELECT NNAME from [VNAME]')
VALUES ('NEW NAME');
Right now I am just trying to test if appending to a linked DBF file works. Any help is appreciated. Thanks!

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?

able to connect to linked server but i cannot select from any table

I have a linked server to a pervasive sql 11 database from my sql server 2012 64bit using ODBC
I am able to see the databases on this server, but when I select * from any table I am getting this error:
OLE DB provider "MSDASQL" for linked server "kslap208" returned message "[Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface][Data Record Manager]The MicroKernel cannot find the specified file(Btrieve Error 12)".
OLE DB provider "MSDASQL" for linked server "kslap208" returned message "[Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Unable to open table: aactual.".
Msg 7306, Level 16, State 2, Line 1
Cannot open the table ""sbxc003"."aactual"" from OLE DB provider "MSDASQL" for linked server "kslap208".
How is it possible that I am able to test the connection succesfully and see all the databases; however, I cannot select?

is it possible to use a provider from a different server?

I may have figured out why I cannot establish a linked server on sql server 2012 using ODBC/OLEDB into a pervasive sql.
I have another sql server 2005 that is able to connect to the pervasive sql because it has a provider called PervasiveOLEDB.11.0.
I would like to use the same provider, and I am wondering if it is possible to get my sql server 2012 to use this provider (which resides on a different server)?\
If not, would there be a different way I could export/import this provider?
I am trying to establish a connection this way, but cannot do it with the provider:
EXEC sp_addlinkedserver
#server = 'kslap208',
#provider = 'MSDASQL',
#datasrc = 'C003',
#srvproduct = 'Pervasive'
GO
update:
although i am able to connect succesfully, i am getting this error when i try to select from tables:
OLE DB provider "MSDASQL" for linked server "kslap208" returned message "Unspecified error".
OLE DB provider "MSDASQL" for linked server "kslap208" returned message "[Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface][Data Record Manager]Cannot locate the named database you specified(Btrieve Error 2301)".
Msg 7311, Level 16, State 2, Line 1
Cannot obtain the schema rowset "DBSCHEMA_TABLES" for OLE DB provider "MSDASQL" for linked server "kslap208". The provider supports the interface, but returns a failure code when it is used.
I think you need to download Pervasive SQL 11 client from here. This should install all drivers

Problem with update sql with excel

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