Pulling data through a linked server is unlikely to be quick especially if you are joining remote tables to local tables. (Just use Profiler to watch what your local server sends to the remote server and I think that you'll be convinced.) Linked Servers are convenient and often "good enough", but not when you start blowing through your batch processing windows.
I have seen overall processing go faster by pulling the remote data into local (temporary or permanent) tables and then "doing the joins" locally to figure out what to put into the production tables.
If you have a large amount of data, I suggest looking into using a SSIS package or bcp and probably bringing the data into a local staging table first and converting the code to run off of local tables. This might involve a lot of surgery to your jobs since you need to have a job step (or steps) to run bcp code and/or packages.
If you are using SQL 2008 or better, MERGE should be available and it could provide more efficient operations. I am unsure if MERGE works with tables on a linked server and, if it does, performance may not be much better than what you have. So, you are still stuck getting the data onto the local server.
Also, you could look into partition switching, but I think would be the most costly thing to do in terms of time spent on getting things to work. You could view it as a learning experience.
Alternatively, you might consider increasing the query timeout, which is a server-level setting on the local server. That might help with the timeout error (until your data volume increases, then you would need to tweak it again), but I doubt that it will help with the TDS error problem.
If you want to minimize the length of time that your production tables are locked (due to the INSERT, not the SELECT with nolock), you would want to get all of the data from the ETL system onto the local box first, then go and insert it all. You want to avoid pulling data for one table, inserting that, pulling the data for the next table, inserting that, etc. (I'm presuming that you are doing all of this in a declared transaction that I'm not seeing.)
I found this article here.
There it states that:
To resolve that problem you have 3 options:
- Run SQL queries from data server (you need to be remotely connected to the database server)
- Enable use of Kerberos on the database server
- Set proxy account for linked server, so that MDX queries are executed in its context instead of in context of the user that is issuing t-sql query:
Create the linked server:
EXEC master.dbo.sp_addlinkedserver
@server = N'SSASSERVER', -- name of linked server
@srvproduct=N'MSOLAP',
@provider=N'MSOLAP', -- see list of providers available on SQL Server under Linked Server node in SSMS Object Browser
@datasrc=N'ServerName', -- machine or instance name that host Analysis Services
@catalog=N'SimplifiedCube' -- Analysis Services database (cube)
and adding a linked server login:
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname=N'SSASSERVER',
@useself=N'False',
@locallogin=NULL,
@rmtuser=N'myDomain\Login',
@rmtpassword='########'
I have basically just done the number 3 and the linked server is working fine for me now.
As you can see on the picture below.
Also I had problems with the timing out so I had to change this setting as well:
(the default is 600)
EXEC sys.sp_configure N'remote query timeout (s)', N'6000'
GO
RECONFIGURE WITH OVERRIDE
GO
This can also be done through the GUI as per the picture below:
Best Answer
On SQL Server 2008 R2 the default value of remote login timeout (s) is five (5) seconds, I believe, though it is configurable.
Since you are now trying to connect to an AWS RDS SQL Server, have you considered whether the remote login timeout (s) is appropriate for this environment?
Try raising the timeout a bit. You might start with 10 seconds:
I have had to bump up the timeout seconds in some environments, so do not be afraid to try this. (It is equally simple to set it back to the previous default.)
You can try to configure a longer timeout, if needed. So far 10 seconds has almost always worked for my environments, but I have gone to 20 seconds a couple of times.