Linked Server in SQL Server Throwing Error - sql-server

I am trying to establish a connection between 2 Server.
IP1 - SQL Server 2008R2
IP2 - SQL Server 2019
I can telnet via port 1433 to these 2 IPs from my system.
I am in My System. I am connected to IP1 using SSMS and executing below queries:
exec sp_addlinkedserver 'IP2';
exec sp_addlinkedsrvlogin 'IP2', 'FALSE', NULL, 'username', 'password';
These above statement ran successfully.
-- Test
SELECT TOP 10 * FROM [IP2].DBName.sys.columns
This statement throws below error.
OLE DB provider "SQLNCLI10" for linked server "IP2" returned message "Client unable to establish connection".
Msg 10054, Level 16, State 1, Line 0
TCP Provider: An existing connection was forcibly closed by the remote host.

Related

Can't connect to Azure SQL Server from 1/3 of our servers

I was trying to create a linked server from an on-premises SQL Server (BadMachine1), to an Azure SQL Server.
Code for creating the linked server
EXEC sp_addlinkedserver D365BI_Testing, '', 'SQLNCLI11', #datasrc='blabla.database.windows.net', #catalog = 'DbName'
EXEC sp_addlinkedsrvlogin D365BI_Testing, 'false', null, 'blabla_Admin', 'thepassword'
Created fine, but when testing connection on BadMachine1, this error message:
TITLE: Microsoft SQL Server Management Studio
------------------------------
The test connection to the linked server failed.
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
TCP Provider: The specified network name is no longer available.
Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server.
OLE DB provider "SQLNCLI11" for linked server "D365BI_Test2" returned message "Client unable to establish connection due to prelogin failure".
OLE DB provider "SQLNCLI11" for linked server "D365BI_Test2" returned message "Client unable to establish connection". (Microsoft SQL Server, Error: 64)
For help, click: https://learn.microsoft.com/sql/relational-databases/errors-events/mssqlserver-64-database-engine-error
------------------------------
BUTTONS:
OK
------------------------------
OK, tested on two other machines we have (GoodMachine1, GoodMachine2) - all of these are in the same data center. The test connection succeeded on both GoodMachine1 and GoodMachine2, and I could successfully write a query from Goodmachine1 and GoodMachine2's SQL Server, to the Azure SQL Server.
Next test:
Tried logging into each of the 3 machines, and opening up SSMS to try to connect to the Azure SQL Db. Connection worked on GoodMachine1 & GoodMachine2. Failed on BadMachine1, with the following error message.
TITLE: Connect to Server
Cannot connect to blabla.database.windows.net.
------------------------------
ADDITIONAL INFORMATION:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Microsoft SQL Server, Error: 64)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=64&LinkId=20476
------------------------------
The specified network name is no longer available
------------------------------
BUTTONS:
OK
------------------------------
I don't have access to check, but I'm told the firewall rules are OK on the Azure side.
There are some characteristics that differ among the 3 machines:
BadMachine1: ODBC Driver 11, old "Microsoft AS OLE DB Provider for SQL Server 2014". SQL Server 2014
GoodMachine1: ODBC Drivers 11, 13, 17, no OLE driver. SQL Server 2016
GoodMachine2: ODBC Driver 13, recent install of OLE driver. SQL Server 2016
Could the old ODBC driver on BadMachine1 be it? Other ideas? Apologies in advance, I've never tired to setup a linked server before, and don't really know what I'm doing very well.
Turns out our IT was blocking those outbound connections from BadMachine1. Now that they're unblocked, the linked server works fine.

cannot link other sql server from linux to a named instance

I have successfully added, linked, and queried other sql servers from linux sql server 2017,
but only with the default instance name. (no instance name)
I cannot connect any other specific instance named servers.
(it's ok from windows sql server2016).
it looks like the backslash + instance name is considered as the hole hostname !?
I tried with double //, \ \ or / ...
is it a known issue or I am doing something wrong ?
I have SSMS 14.0.17119.0 on Windows 8.1 Pro,
Microsoft SQL Server 2017 (CTP2.1) - 14.0.600.250 (X64)
May 10 2017 12:21:23
Copyright (C) 2017 Microsoft Corporation. All rights reserved.
Developer Edition (64-bit) on Linux (Ubuntu 17.04)
I tried with the user inteface on SSMS, and with T-SQL
Exec master.dbo.sp_addlinkedserver ...
and receive this error message which I beleive is not the real error:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
OLE DB provider "SQLNCLI11" for linked server "SAGE-10\L1000" returned message "Login timeout expired".
OLE DB provider "SQLNCLI11" for linked server "SAGE-10\L1000" 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.". (Microsoft SQL Server, Error: -1)
I had the same issue. Luckily in my case the linked instance had been set up to listen to another static tcp port. So I could use that as a workaround.
If you have to option to change the server you are linking to, you can set the tcp port in SQL Server Configuration manager - Network configuration - Protocols for INST2 - TCP/IP - properties - IP Addresses - TCP port.
After that I could add the linked server like this. Port number is 1435.
EXEC master.dbo.sp_addlinkedserver #server = N'Server20_inst2', #srvproduct=N'', #provider=N'SQLNCLI', #datasrc=N'192.168.1.112,1435', #catalog=N'Test'
EXEC master.dbo.sp_addlinkedsrvlogin
#rmtsrvname=N'Server20_inst2', #useself=N'False', #locallogin=NULL, #rmtuser=N'sa', #rmtpassword='##########'
When you try to connect to SQLEXPRESS often port is set randomized. In my instance is set to 61423. To verify port number on server you can do this:
SELECT DISTINCT local_net_address, local_tcp_port FROM sys.dm_exec_connections
Then for example:
EXEC master.dbo.sp_addlinkedserver #server = N'Server20_inst2', #srvproduct=N'', #provider=N'SQLNCLI', #datasrc=N'192.168.1.112,61423', #catalog=N'Test'

SELECT Query between two different servers

I want to pull out data from different tables from different servers. I took a query at V5\SQL2014 Server and run these following to connect to V5_27\SQL2005 Server
EXEC sp_addlinkedserver
#server= 'V5_27\SQL2005',
#srvproduct='V5_27\SQL2005',
#provider='SQLNCLI',
#datasrc='tcp:0.0.0.0'
EXEC sp_addlinkedsrvlogin
#useself='FALSE',
#rmtsrvname='V5_27\SQL2005',
#rmtuser='sa',
#rmtpassword='123'
SELECT * FROM Stk006,[V5_27\SQL2005]..[TESTACC].Stk006
It shows me following errors.
OLE DB provider "SQLNCLI11" for linked server "V5_27\SQL2005" returned message "Login timeout expired".
OLE DB provider "SQLNCLI11" for linked server "V5_27\SQL2005" 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 10049, Level 16, State 1, Line 22
TCP Provider: The requested address is not valid in its context.
User and Password are not wrong.
Allow remote is enabled in both servers.
TCP/IP and Named Pipes are enabled in both servers.
Please help me, thanks!
Thanks everyone, I found a solution for my problem.
You can check the solution link here or do below steps.
Try to create a linkServer , Object Explorer -> Server Objects -> Linked Servers (Right click and create new)
Configure Settings
Enter your Server Name
Login with sa and password
Then Test Connection of it.
Enjoy your query.
select
lc.t2 as 'Local Stock Code',
ext.t2 as 'External Stock Code'
from
Stk001 lc,
[V5_27\SQL2005].[TESTACC].[dbo].[STK001] ext

Restore big database from SQL server 2014 into SQL Server 2008

I just bought a new 2008 SQL server license and am now trying to move my 10gb database from 2014 express(12.0.5203) to 2008 (10.0.1600.22)
I have tried the "export DB to script" way, but the file is very big(20GB) and a lot of data is not getting imported because of several datatype convertion errors.
Currently I am trying to copy the data by scripts like
SELECT *
INTO database.dbo.table
FROM OPENQUERY([localhost\WAWI], ' SELECT *
FROM [localhost\WAWI].database.dbo.[table]')
While having created a connection in sys.servers
EXEC sp_addlinkedserver #server='WAWI'
EXEC sp_addlinkedsrvlogin 'localhost\WAWI', 'false', NULL, 'sa', 'password'
But while executing the import script I am not able to connect to the local 2014 server even so I have opened it in the object explorer in a query window opened by the remote 2008 server
I get the following error message
The OLE DB provider 'SQLNCLI10' for linked server 'WAWI' has the message 'Login timeout expired' return.
The OLE DB provider 'SQLNCLI10' for linked server 'WAWI' has the message ' network-related or instance-specific error when establishing a connection to SQL Server. The server could not be found, or it can not be accessed. Verify that the instance name is correct and that allows SQL Server remote connections. For more information in SQL Server Books Online.' return.
Message 53, level 16, State 1, line 20
Named pipes provider: it could be made cannot connect to SQL Server [53].

I created a Linked server to SQL Azure but cannot see tables in the Management Studio view?

I ran all the following:
On the remote master database:
CREATE LOGIN user1
WITH PASSWORD = 'Password22++'
GO
On the remote authentication database:
CREATE USER user1
FOR LOGIN user1
WITH DEFAULT_SCHEMA = authentication
GO
EXEC sp_addrolemember N'db_owner', N'user1'
GO
On the local database:
EXEC master.dbo.sp_addlinkedserver
#server = N'AZ3',
#srvproduct=N'Any',
#provider=N'MSDASQL',
#datasrc=N'AZ3'
GO
EXEC master.dbo.sp_addlinkedsrvlogin
#rmtsrvname=N'AZ3',
#useself=N'False',
#locallogin=NULL,
#rmtuser=N'user1',
#rmtpassword='Password22++'
GO
I see the linked server has been created but when I look at it and try to see the following message:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo) The OLE DB Provier
"MSDASQL" for linked server "AZ3" reported an error.
Authentication failed.
Are there some more roles I should grant?
Also if I just want to do a select on a table such as the 'ABC' table in the database authentication on the remote then how should I code that SQL ?
Here's what I tried:
SELECT * FROM OPENQUERY([AZ3],'SELECT * FROM dbo.AspNetRoles')
But this also gives me an error:
OLE DB provider "MSDASQL" for linked server "AZ3" returned message "[Microsoft][SQL Server Native Client 11.0][SQL Server]Statement(s) could not be prepared.".
OLE DB provider "MSDASQL" for linked server "AZ3" returned message "[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'dbo.AspNetRoles'.".
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "MSDASQL" for linked server "AZ3".

Resources