SQLNCLI syntax error when using OPENROWSET in SQL Server 2019 - sql-server

SQLNCLI syntax when using OPENROWSET
We have been using this syntax when using OpenRowset to collect data from other SQL Server instances.
SELECT a.* FROM OPENROWSET('SQLNCLI', 'Server=MyServer;Database=Tasks; User Id=sa;Password=myPassword;','SELECT * FROM Patients') As a;
I am facing following some errors.
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid authorization specification".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid connection string attribute".
The OLE DB provider "SQLNCLI" for linked server "(null)" reported an error. Authentication failed.
Cannot initialize the data source object of OLE DB provider "SQLNCLI11" for linked server "(null)".

I resolved my error using following query.
I replaced SQLCLI with MSDASQL and wrote driver name as SQL Server.
select a.* from openrowset('MSDASQL', 'Driver={SQL SERVER}; Server=MYINSTANCE;UID=mySQLUser; PWD=*******;', 'select * from sys.databases') as a

Related

Cannot create a linked server for Sage Line 50 to SQL Server using the 64 bit driver for Sage

I have a Sql Server 2019 Express database to which i want to create a linked server to Sage Line 50.
Now i have installed the 64 bit ODBC driver for Sage Line 50 (see attached Screenshot) and then proceeded to set up the linked server (see screenshot)
Now i put credentials in but get the following error message
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "SAGELINE50REPORTS".
OLE DB provider "MSDASQL" for linked server "SAGELINE50REPORTS" returned message "The driver returned invalid (or failed to return) SQL_DRIVER_ODBC_VER: 27.2]".
OLE DB provider "MSDASQL" for linked server "SAGELINE50REPORTS" returned message "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed".
OLE DB provider "MSDASQL" for linked server "SAGELINE50REPORTS" returned message "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed".
OLE DB provider "MSDASQL" for linked server "SAGELINE50REPORTS" returned message "Cannot find all files in data path". (Microsoft SQL Server, Error: 7303)
what am i doing wrong here?

OPENROWSET From SQL to Oracle

i'm trying to connect from sql server to oracle server with OPENROWSET for fetch data.
this is my query:
SELECT a.*
FROM OPENROWSET(N'OraOLEDB.Oracle', N'Data Source=Myip:Port/dbname';'User Id=user';'Password=pass;',
'select * FROM view WHERE value = ''102030'' ') AS a;
sql return below error:
OLE DB provider "OraOLEDB.Oracle" for linked server "(null)" returned
message "ORA-12154: TNS:could not resolve the connect identifier
specified". Msg 7303, Level 16, State 1, Line 23 Cannot initialize the
data source object of OLE DB provider "OraOLEDB.Oracle" for linked
server "(null)".
how can i fix this ?
I used Linked Server for fetch data but oracle table not small and it takes a long time to execute.

OLE DB provider "OraOLEDB.Oracle" for linked server returned message "ROW-00004: Invalid column datatype"

The following SQL running in SQL Server
select *
from openquery(oracle_ls,'select xmlelement("Test") from dual')
returns the error
OLE DB provider "OraOLEDB.Oracle" for linked server "oracle_ls" returned message "ROW-00004: Invalid column datatype".
How to return Oracle XML type via linked server?
OLEDB driver complains as the data type is not supported.
However when you convert the xml to string, it should work.
select * from openquery(oracle_ls,
'select xmlelement("Test").getstringval() from dual')

Call Oracle function with ref cursor output in SQL Server linked server?

How do I need to call an Oracle function with ref cursor output in a SQL Server linked server?
I used this statement:
SELECT *
FROM OPENQUERY(oracle, 'select * from functionname(''N'',''2016-11-01'')')
but I get this error
OLE DB provider "OraOLEDB.Oracle" for linked server "oracle" returned message "ORA-00933: SQL command not properly ended".
Msg 7321, Level 16, State 2, Line 33
An error occurred while preparing the query "select * from functionname('N','2016-11-01')" for execution against OLE DB provider "OraOLEDB.Oracle" for linked server "oracle".
Any help?
Maybe this will help?
Calling an Oracle function from SQL Server Linked Server
EXECUTE (Query, Parameters) AT LinkedServerName

T-SQL, OPENROWSET copying tables between databases on the same server

I am developping some code that transfers data between SQL servers. In this phase, all my work is on the same server (local, where I am the owner), but I am already trying to implement the OPENROWSET functionnalities that will be used at production time (where data will be on different servers and where I will have to build queries for the transfers). The following 3 codes are supposed to do the very same thing, but the one making use of OPENROWSET is giving me an error ... Bref, I am stuck! if anyone could help...
3 parts naming: works
USE db1
SELECT * INTO dbo.myTable FROM db2.dbo.myTable
OPENDATASOURCE: works
USE db1
SELECT * INTO dbo.myTable FROM OPENDATASOURCE
('SQLOLEDB',
'Data Source=127.0.0.1\SQLEXPRESS;Integrated Security=SSPI'
).db2.dbo.myTable
OPENROWSET: does not work
USE db1
SELECT * INTO dbo.myTable FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=(Local)',
'db2.dbo.myTable')
Where I am getting the following message:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.".
Of course I have tried to use the standard properties of my connection string (as with OPENDATASOURCE) but I was also getting the following error:
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid authorization specification".
OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid connection string attribute".
For one thing: Your OPENROWSET statement isn't specifying the server instance.
Try
USE db1
SELECT * INTO dbo.myTable FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=127.0.0.1\SQLEXPRESS',
'db2.dbo.myTable')

Resources