Linked Server Connectivity Issues? - sql-server

My linked server was fine until now and i was selecting data using some join statement for filtering the but suddenly its returning following error. i cannot execute any query against my linked server.
Linked server is still available as i tried a TEST CONNECTION from server object and it was successful
Msg 65535, Level 16,State 1, Line 0
Sql Server Interface:Error Loading Server/Instance Specified
(xfffffff)
oledb provider sqlnc111 for linked server "MSNAC/MSDB5" returned an
error " A login time out expired
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.
How to solve this issue ?

If nobody has made any configuration changes, your queries may be timing out because of a big data change. Try to, at least temporarily, set the following option:
USE Yourdatabase;
GO
EXEC sp_configure 'remote query timeout', 0;
GO
RECONFIGURE;
GO
If it goes fine with these settings, your queries were simply timing out because of the set limit. Experiment a bit with your queries, see what is an appropriate limit to put in this properties (leaving it to infinity isn't a good idea) and reconfigure once again.
NOTE: the number is in seconds.
To read up more on this issue, check the documentation for remote query timeout.

Related

How to add Sybase SQL Anywhere DB as linked server to MS SQL Server properly

I used the Microsoft OLE DB Provider for SQL Anywhere to create a linked server, it shows remote databases and tables, I can read data, but writing data seems to work only using OPENQUERY() and when doing the connection_authentication using EXEC ... AT ... directly in the script.
How can I have the SQL Server do the authentication automatically when opening a connection?
How can I make normal write operations work without OPENQUERY()?
Sorry for not adding detailed error messages, I will add them later maybe, when I have access to the server again... But they were not meaningful anyway, i.e. when the weird authentication was missing, it just said "could not insert" or "failed" instead of indicating any authentication issue.
How to get the real error messages that come from Sybase?
Details:
SAP Sybase SQL Anywhere 16 (OEM Authenticated Edition) <-> MS SQL Server 2014
EXEC 'SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=''Company=...''' AT linkedserver
INSERT INTO OPENQUERY(linkedserver, 'SELECT column FROM table WHERE 0=1') VALUES ('')
...that's not nice.
Even more details:
This is how I created the linked server
This is the authentication I'm talking about

Resource limit error in linked server

I have a problem with running a query in a linked server, I use sql sp’s for ETL process in my BI project
(For some reason I cannot use ssis).one of my queries witch has to read recently changed records and insert them in my warehouse take too long to execute and always fail with this error:
OLE DB provider 'SQLOLEDB' reported an error for linked server ‘XXX’. Execution terminated by the provider because a resource limit was reached..
But other queries run successfully. I also run following scrip in my linked server (warehouse) to increase timeout threshold.
sp_configure 'remote login timeout', 30
go
reconfigure with override
go
sp_configure 'remote query timeout', 0
go
reconfigure with override
go
Hint: I’ve used change tracking option in source tables to track updates and inserts..
I would be really thankful if someone could help me out of this.

SQL Server Linked Server, Error running query firebird

I'm doing a query on the firebird external database from SQL Server (2008, 2012). The server connects seamlessly to the linked server, but to consult the following error.
ADDITIONAL INFORMATION:
Object reference not set to an instance of an object. (Microsoft.SqlServer.ConnectionInfo)
===================================
You can not run the script.
===================================
Object reference not set to an instance of an object. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Program location:
on Microsoft.SqlServer.Management.Common.ConnectionManager.UpdateDatabaseEngineType()
on Microsoft.SqlServer.Management.Common.ConnectionManager.get_DatabaseEngineType()
on Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptAndResultsEditorControl.DebugWrapper.Start()
on Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptAndResultsEditorControl.OnDebugScript(Object sender, EventArgs a)
The query worked until a few days ago, but now I get this error.
Might be wrong?
this is the query:
SET #QUERYSTRING = 'SELECT #HAST=HASTA, #ABON=ABONOCONTRATO FROM OPENQUERY( CnxAdasysWS, ''SELECT first 1 HASTA, ABONOCONTRATO FROM TBLPAGOS WHERE TM=0 AND ANULADO=0 AND IDCONTRATO ='''''+#NOCONTRATO+''''' ORDER BY IDGENERADOR DESC'')';
EXECUTE SP_EXECUTESQL #QUERYSTRING, N'#HAST DATE OUTPUT, #ABON FLOAT OUTPUT', #HAST=#PAGOHASTAMOVIL OUTPUT, #ABON=#ABONOCONTRATO OUTPUT
I run the query in SQL management studio and came out the same mistake as I configured the linked server several times, but no error above shows create. Connection test shows no problems
It's not easy to identify the problem outside of your network. The think I've in mind is verify if the connections between the servers are OK, firewalls servers and security rules.
Try to make a simple select between the servers to be sure that the connections are working well.

The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server was unable to begin a distributed transaction

I'm trying to run a distributed transaction from my machine (SQL Server 2012) to a client server (SQL Server 2008).
I'm trying to run:
begin distributed transaction
select * from [172.01.01.01].master.dbo.sysprocesses
Commit Transaction
and I get:
OLE DB provider "SQLNCLI11" for linked server "172.01.01.01" returned message "No transaction is active.".
Msg 7391, Level 16, State 2, Line 2
The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "172.01.01.01" was unable to begin a distributed transaction.
I can run a SELECT to that server with data coming back, so at least I know the servers can see each other, and the Linked Server exists and is operating
Now, there are multiple posts on the web for this, but I can't get it to work. This is what I have tried so far:
Set DTC properties to the following (on both server)
Restarted the Distributed Transaction Coordinator (MSDTC) from Control Panel -> Services (on both servers).
Uninstalled and installed DTC (on both servers).
Restarted the remote server.
Turned off the firewall on both servers.
Enabled sp_configure 'Ad Hoc Distributed Queries', 1 (on both servers).
I ran DTCPing and it pinged successful.
Linked server properties changed to the following:
What else are there to try?
UPDATE:
Running the transaction from another server to 172.01.01.01 works.
Therefore the issue is not on the destination server, but on my machine which is the source.
Setting "Enable promotion of distributed transaction" flag to false (in Linked Server Properties Window) solved my similar problem.
I faced a similar problem and I resolved it as follows. There is a node in tree structure of object explorer in SQL Server. There you will find Serverobjects → LinkedServers → below that there is a list of IP addresses of distributed servers.
Right click on it, select properties, a window will pop up. Select server options in the left pane; you will get list of properties. Set the flag value false to the property "Enable promotion of distributed transaction".
If after configuring your MS Distributed Transaction Coordinator (MSDTC) on the two SQL server's according to the OP's original post, you still get "no transaction active", you should check that each host is reachable via the IP (assuming that's what you've used) registered in the linked server.
For example; on a recent setup, two SQL servers were reachable through a network in the 192.168.200.x range (same subnet), but each server was also indirectly connected through an IP in the 10.x.x.x range. On one SQL Server, the DNS server it used kept resolving the target SQL server to it's 10.x.x.x IP (which was firewalled) even though the linked server entry used the IP in the 192.168.200.x of the target server.
It appears that MSDTC uses the hostname of the server, while SQL server connects over any linked connection using the IP or hostname defined in the linked server entry, leading to this confusing behaviour of apparent connectivity when checking the target linked server within SQL Management Studio, but inability to execute remote procedures on the target.
The solution was to add entries in the host file's (%windir%\system32\drivers\etc\hosts) to explicitly force each SQL server to resolve the other to the IP address on the 192.168.200.x network.
On host 1 (IP 192.168.200.15):
# TARGET SERVER
192.168.200.20 targetserverhostname.and.any.domain.suffix targetserverhostname
On host 2 (IP 192.168.200.20)
# SOURCE SERVER
192.168.200.15 sourceserverhostname.and.any.domain.suffix sourceserverhostname
Don't forget to ensure MSDTC has been configured according to the OP's screenshot above allowing network access and (if required) No Authentication.
try this SQL above your begin distributed transaction
set XACT_ABORT on
I had a similar problem. Went through all the things listed to no avail. We have a cluster environment and it turns out our DBA was doing the services work on the cluster and not the main server. Worth keeping that in mind if all else fails :-)
Condition like this may cause same error:
1- Run a transactional script like this and read from linked server:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
Begin Tran
... (select command from linked server)...
Commit
2- Open a new connection in code and run a non-transactional script
Result: Error will raised!
Solution: Remove SET TRANSACTION ISOLATION LEVEL SERIALIZABLE.
Fix:
Make sure the “Enable Promotion of Distributed Transaction” is set to “False” on the linked server property.
EXEC master.dbo.sp_serveroption #server=N'yourlinkedservername', #optname=N'remote proc transaction promotion', #optvalue=N'true'
“remote proc transaction promotion” is a new option on SQL Server 2008, which allows you to control whether or not you want to enlist remote stored procedure call in a distributed transaction. When this option is off (FALSE), the local transaction will not be promoted to distributed transaction. This is how we are able to separate outer and inner transactions in a “autonomous transaction” fashion.
Source:
https://www.eugenechiang.com/2020/09/17/linked-server-error-no-transaction-is-active/

Possible to set SQL Server Remote Query Timeout per Query for Linked Server calls?

For linked servers, I see how it is possible to change the "remote query timeout" configuration to hint a call to a linked server should complete or rollback within the specific timeout value. This appears to work across the SQL Server engine--is it possible to change the hint within a stored procedure, so that a specific stored procedure could run longer if needs to, but all other non-hinted SPROCs would timeout quicker if they run long?
Linked Query Timeout is discussed here:
http://support.microsoft.com/kb/314530
Example code to set it to timeout in 3 seconds is here:
sp_configure 'remote query timeout', 3
go
reconfigure with override
go
Not really advisable to change it within a stored procedure. remote query timeout is a global server setting when altered with sp_configure, so changing it in a stored procedure affects all remote queries for all linked servers on the server.
Additionally, executing sp_configure requires the ALTER SETTINGS server permission, which typically only sysadmin and serveradmin have. Granting these permissions to a data access account would be a security concern since they could potentially take your server down with sp_configure commands.
What I would suggest is creating a second linked server with a different name that you would use with just this one stored procedure. You can, in SSMS, configure a query timeout for each individual linked server. Adding a second linked server would enable you to query the same server with different linked server client settings. You might need to create a DNS CNAME to accomplish this if you're using plain SQL Server Linked Servers.

Resources