<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Testing' and 'Linked server'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Testing,Linked+server&amp;orTags=0</link><description>Search results matching tags 'Testing' and 'Linked server'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Linked servers: how long do they stay connected?</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2011/03/31/linked-servers-how-long-do-they-stay-connected.aspx</link><pubDate>Fri, 01 Apr 2011 00:36:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34537</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;I was looking at some of my old notes on linked servers and found a tidbit on how the linked server connections are managed by SQL Server. I'm posting it here because&amp;nbsp;I don’t think the information is widely known.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;When you make a linked server call from a SQL Server instance (say ServerA) to another SQL Server instance (say ServerB) over Microsoft Native Client OLEDB Provider, SQL Server on ServerA acts as a client to the instance on ServerB and will open or reuse a connection to ServerB. That connection will be managed by the SQL Server instance on ServerA.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;If you check on ServerB with the following query, you should see that connection from ServerA (if it's still there):&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select * from sysprocesses&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;where hostname = 'ServerA'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 10pt;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and program_name = 'Microsoft SQL Server'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;And if no linked server calls from ServerA is using the connection, its status would be ‘dormant’.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;The question is, “how long will ServerA keep the connection alive if no call&amp;nbsp;is using it? And can you configure&amp;nbsp;it?”&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;I can’t find any official documentation to answer these two questions. But my own tests appear to yield a consistent answer to the first question. That is, a dormant SQL Server linked server connection will stay for about 4~5 minutes, and will be closed after that. All my attempts to see if this number is configurable suggest that the answer is negative. If anyone knows a more authoritative answer, please post it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;Here is&amp;nbsp;a simple&amp;nbsp;test to determine how long a dormant connection stays alive.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;On ServerB, use the&amp;nbsp;previous query to ensure that there is no&amp;nbsp;linked server connection from ServerA. If there is, kill the connection and ensure ServerA does not open a new one.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 10pt;"&gt;&lt;FONT face=Calibri size=3&gt;On ServerB, run this script:&lt;/FONT&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;declare @dt datetime&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;while not exists (select * from sysprocesses&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where hostname = 'ServerA'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and program_name = 'Microsoft SQL Server')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;waitfor delay '00:00:01'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;set @dt = getdate()&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;while exists (select * from sysprocesses&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;where hostname = 'ServerA'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;and program_name = 'Microsoft SQL Server')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;waitfor delay '00:00:01'&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select 'Duration' = datediff(second, @dt, getdate())&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;FONT face=Calibri size=3&gt;Go to ServerA and run the next script:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;
&lt;P class=MsoNormal style="BACKGROUND:#ddd9c3;MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;mso-background-themecolor:background2;mso-background-themeshade:230;"&gt;&lt;SPAN style="FONT-SIZE:12pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select * from openquery(ServerB, 'select @@servername')&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 0pt;LINE-HEIGHT:normal;mso-layout-grid-align:none;"&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;&lt;BR&gt;I have been consistently getting the Duration values between ~260 seconds and ~300 seconds, which is about 4~5 minutes. &lt;/FONT&gt;&lt;FONT face=Calibri size=3&gt;If you have any test numbers of your own &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;or run this test, please post your findings.&lt;/FONT&gt;&lt;/P&gt;</description></item></channel></rss>