<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Dipanjan's WeBlog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/dipanb/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/dipanb/feed.xml</link>
    <description>From Impossible to I-M-Possible</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:38:38 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>You may see weird behavior when using the SSIS Object Model from an ASP.NET application</title>
      <link>https://docs.microsoft.com/archive/blogs/dipanb/you-may-see-weird-behavior-when-using-the-ssis-object-model-from-an-asp-net-application</link>
      <pubDate>Thu, 14 Jul 2011 09:52:30 GMT</pubDate>
      <dc:creator><![CDATA[Dipanjan Banik]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dipanb/2011/07/14/you-may-see-weird-behavior-when-using-the-ssis-object-model-from-an-asp-net-application/</guid>
      <description><![CDATA[SSIS comes along with a rich set of application programming interfaces (APIs) for programming the...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="Verdana">SSIS comes along with a rich set of application programming interfaces (APIs) for programming the Integration Services object model. You can extend packages by writing components that become available within SSIS Designer to provide custom functionality in a package. You can create, configure, and run packages programmatically from your own applications. The SSIS object model can be used either from a windows or a web based application. However using it from an ASP.NET application may not always give you the most expected results. Some of the pros and cons are discussed in this <a href="https://blogs.msdn.com/b/michen/archive/2007/03/22/running-ssis-package-programmatically.aspx">blog</a>.</font></p>  <p><font size="2" face="Verdana">Recently I was working with a customer who was trying execute a SSIS package programmatically from an ASP.NET application. The package used the SendMail task to send emails to user. The task had three properties which were being evaluated using an expression from local SSIS variables. The values of the local variables were dynamically being passed from the ASP.NET application. Everything worked fine but sometimes the package failed from the ASP.NET application. As opposed to this, the package ran successfully every time from BIDS or from Management Studio. If I use the same code to execute the package from a console app, it ran successfully every time. So there was something different from the ASP.NET application. To understand it better, I set up a repro in my lab machine and also did some instrumentation to my code. The variable values were being updated properly but still the package failed. On Error event handler captured the following error:</font></p>  <div id="codeSnippetWrapper">   <pre id="codeSnippet" class="csharpcode">Microsoft.SqlServer.Dts.Runtime.TaskHostThe result of the expression <br /><span class="str">&quot;@[User::MailRecipient]&quot;</span> on property <span class="str">&quot;ToLine&quot;</span> cannot be written to the property. <br />The expression was evaluated, but cannot be set on the property.<br /></pre>
</div>

<p><font size="2" face="Verdana">I also observed that I cannot access the Properties.GetValue or Properties.SetValue of the TaskHost object as described in </font><a href="https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.tasks.sendmailtask.sendmailtask.aspx"><font size="2" face="Verdana">here</font></a><font size="2" face="Verdana">. 
    <br />If you try this from a console app, it works fine, but breaks every time from an ASP.NET application. Getting this exception:</font></p>

<p><font size="2" face="Consolas">Attempted to access an unloaded AppDomain. 
    <br />[AppDomainUnloadedException: Attempted to access an unloaded AppDomain.] 

    <br />Microsoft.SqlServer.Dts.Runtime.DtsProperty.SetValue(Object o, Object value) +146 

    <br />SSISWebApp._Default.Page_Load(Object sender, EventArgs e) in D:\SSISWebApp\SSISWebApp\Default.aspx.vb:73 

    <br />System.Web.UI.Control.OnLoad(EventArgs e) +91 

    <br />System.Web.UI.Control.LoadRecursive() +74 

    <br />System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207</font></p>

<p><font size="2" face="Verdana">Surprisingly every time I made any changes in my ASP.NET code and rebuild my assembly, I landed into these errors until I recycle my app pool. Once I recycle the app pool the code executes without any error. We did some live debugging and found that it’s a bug in the SSIS object model. </font></p>

<p><font size="2" face="Verdana">What we discovered is that within the w3wp process, our DTS assemblies are stored within the Shared AppDomain whereas the actual ASP.NET application is housed in a separate AppDomain for itself.&#160; When any change is made to the assembly in the project AppDomain, it is completely torn down due to ASP.NET AppDomain’s inability to dynamically load DLLs.&#160; When this occurs, any subsequent attempts to access the properties on a TaskHost fails due to some vestigial reference in our code in the shared AppDomain back to the original. Recycling the AppPool resolves the issue, but any subsequent updates to the application will require another recycle. The issue occurs due to caching that our DLLs do in order to avoid doing reflection multiple times on COM components.&#160; Cross AppDomain interactions have long been established as a weak point of SSIS due to this limitation.</font></p>

<p><font size="2" face="Verdana">Also, the issue is not limited to our SendMail Task. It would occur on any Tasks/Components since they all boil down to underlying COM objects. Users would face this behavior more on their test environments as compared to production. Because while testing we intend to change our code multiple times and rebuild our app but we seldom do that in production. If you are facing the above issue I would recommend two simple workarounds:</font></p>

<ol>
  <li><font size="2" face="Verdana">Isolate your application in a separate application pool.</font> </li>

  <li><font size="2" face="Verdana">Recycle your app pool every time you rebuild your assembly. Since the app is running on a separate app pool, it wont affect other applications.</font>&#160; </li>
</ol>]]></content:encoded>
    </item>
    <item>
      <title>Query Designer in SSIS 2008 builds bad query when column name is same as table name with SQLNCLI10 Provider</title>
      <link>https://docs.microsoft.com/archive/blogs/dipanb/query-designer-in-ssis-2008-builds-bad-query-when-column-name-is-same-as-table-name-with-sqlncli10-provider</link>
      <pubDate>Thu, 19 May 2011 16:36:00 GMT</pubDate>
      <dc:creator><![CDATA[Dipanjan Banik]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dipanb/2011/05/19/query-designer-in-ssis-2008-builds-bad-query-when-column-name-is-same-as-table-name-with-sqlncli10-provider/</guid>
      <description><![CDATA[I was working on a case yesterday and an interesting issue came up. A customer was migrating an SSIS...]]></description>
      <content:encoded><![CDATA[<p><font color="#000000" size="2" face="Verdana">I was working on a case yesterday and an interesting issue came up. A customer was migrating an SSIS 2005 package to 2008. While doing so, he was trying to modify the query from the Query Builder in the OLEDB Source. The Query Designer was surprisingly modifying the query into a bad syntax and that was resulting into a Syntax error. But if we don’t use the Query Designer the query was being parsed without any error. I was able to repro the issue with this query:</font></p>  <div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; height: 51px; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">SELECT</span> CustomerName.CustID, CustomerName.City, CustID.PhoneNo<br /><span style="color: #0000ff">FROM</span> CustomerName <span style="color: #0000ff">INNER</span> <span style="color: #0000ff">JOIN</span><br /><br />CustID <span style="color: #0000ff">ON</span> CustomerName.CustID = CustID.CustID</pre>

  <br /></div>

<p><font color="#000000" size="2" face="Verdana">Notice that the table CustID has a column with the same name, i.e. CustID. As a result the query was being modified inside Query Designer:</font></p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet" class="csharpcode"><span style="color: #0000ff" class="kwrd">SELECT</span> CustomerName.CustID, CustomerName.City, dbo.CustomerName.CustID.PhoneNo<br /><span style="color: #0000ff" class="kwrd">AS</span> Expr1<br /><span style="color: #0000ff" class="kwrd">FROM</span> dbo.CustomerName <span style="color: #0000ff" class="kwrd">INNER</span> <span style="color: #0000ff" class="kwrd">JOIN</span><br />dbo.CustID <span style="color: #0000ff" class="kwrd">ON</span> CustomerName.CustID = dbo.CustomerName.CustID.CustID</pre>

  <br /></div>

<p><font color="#0000ff" size="2" face="Verdana"><font color="#000000">However if we open up a Query Designer and try to build the query inside it from scratch, it was able to create it. But if we provide it with a pre-written query which has a column name same as its table name, it was not able to reverse engineer the query. I tested this with the Management Studio Query Designer, and that does not have this issue. I also tested it with BIDS 2005 Query Designer and that does not have this issue either.</font> </font></p>

<p><font color="#000000" size="2" face="Verdana">It was odd because the Query Designer code base was not really changed. So the only difference I can see is the provider it was using to build the Query. BIDS 2005 OLEDB Source uses a connection manager with the SQLNCLI OLEDB Provider. When we migrate the package to SSIS 2008, the provider automatically changes to SQLNCLI10. Whereas when you use the same Query Designer from SQL Management Studio, it will use .NET SqlClient Provider. </font></p>

<p><font color="#000000" size="2" face="Verdana">An easy workaround to avoid this would be to use the OLEDB Source in SSIS 2008 with a connection manager using the SQLNCLI Provider instead of SQLNCLI10.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>You may see an instant timeout when connecting to a SQL Server Mirrored database from a .Net application</title>
      <link>https://docs.microsoft.com/archive/blogs/dipanb/you-may-see-an-instant-timeout-when-connecting-to-a-sql-server-mirrored-database-from-a-net-application</link>
      <pubDate>Sat, 14 May 2011 19:19:00 GMT</pubDate>
      <dc:creator><![CDATA[Dipanjan Banik]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dipanb/2011/05/14/you-may-see-an-instant-timeout-when-connecting-to-a-sql-server-mirrored-database-from-a-net-application/</guid>
      <description><![CDATA[I can't take the credit for all this content as many of my colleagues were part of the investigation...]]></description>
      <content:encoded><![CDATA[<font color="#000000" size="2" face="Verdana">I can't take the credit for all this content as many of my colleagues were part of the investigation on this issue. But I feel its worthwhile to share the details as many customers are facing this problem. </font>  <p><font color="#000000" size="2" face="Verdana">Consider you have a .Net application which is connecting to a SQL Server 2005 or 2008 database which is mirrored to another instance of SQL Server using the .NET SQLClient Provider. Intermittently you may see connectivity errors from your application with the following stack trace:</font></p>  <p><font color="#000000" size="2" face="Courier New">Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.      <br />at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)       <br />at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()       <br />at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)       <br />at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)       <br />at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()       <br />at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean&amp; marsCapable)       <br />at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)       <br />at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)       <br />at System.Data.SqlClient.SqlInternalConnectionTds.LoginWithFailover(Boolean useFailoverHost, ServerInfo primaryServerInfo, String failoverHost, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)</font></p>  <p><font color="#000000" size="2" face="Verdana">What is more surprising is that the timeout happens instantaneously, like within a second. Ideally you would expect to get a timeout after 15 seconds (the default connection timeout), buts that’s not the case.</font></p>  <p><font color="#000000" size="2" face="Verdana">If we take a </font><font color="#000000" size="2" face="Verdana"><a href="https://www.microsoft.com/downloads/en/details.aspx?FamilyID=983b941d-06cb-4658-b7f6-3088333d062f&amp;displaylang=en">Netmon</a></font><font color="#000000" size="2" face="Verdana"> trace, here is what we see:</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/5277.Capture_thumb3_3B86EFE6.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/5277.Capture_5F00_thumb3_5F00_3B86EFE6.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Capture_thumb3" border="0" alt="Capture_thumb3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/2134.Capture_thumb3_thumb_48ED02EC.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/2134.Capture_5F00_thumb3_5F00_thumb_5F00_48ED02EC.jpg" width="845" height="157" /></a></p>  <p><font size="2" face="Verdana">In this example we can see the app server closes the connection close to 1 sec during the TDS: Prelogin. When the SQL Server responds back in 5 sec its too late and client will reset the connection.</font></p>  <p><font size="2" face="Verdana">As per the </font><a href="https://msdn.microsoft.com/en-us/library/ms365783.aspx"><font size="2" face="Verdana">Connection Retry Algorithm for Mirroring</font></a><font size="2" face="Verdana">, SqlClient code takes the connection timeout and multiplies it by 0.08 to determine the milliseconds to wait for first read (SniReadSync call). Now if this first SniReadSync fails due to a timeout (due to a slow response from the server), the connection is incorrectly set to a doomed state by the sqlClient .NET Provider and this causes the connection attempt to prematurely fail before the entire connection timeout expires.</font></p>  <p><font size="2" face="Verdana">Similarly if you look into the Connectivity Ring Buffer in SQL Server, you will notice that the entire login process got timed out in a short timeframe of milliseconds.</font></p>  <p><font size="2" face="Verdana">You can run the following query to get the ring buffer output from Management Studio:</font></p>  <div id="codeSnippetWrapper">   <div id="codeSnippetWrapper">     <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">CAST</span>(record <span style="color: #0000ff">AS</span> XML) <span style="color: #0000ff">FROM</span> sys.dm_os_ring_buffers <br /><span style="color: #0000ff">WHERE</span> ring_buffer_type = <span style="color: #006080">'RING_BUFFER_CONNECTIVITY'</span></pre>

    <br /></div>

  <div><font size="2" face="Verdana">You can find more about Connectivity Ring Buffer from </font><a href="https://blogs.msdn.com/b/sql_protocols/archive/2008/05/20/connectivity-troubleshooting-in-sql-server-2008-with-the-connectivity-ring-buffer.aspx"><font size="2" face="Verdana">here</font></a><font size="2" face="Verdana">.</font></div>
</div>

<p><font size="2" face="Verdana">But all of the above were symptoms of this issue. So how can you be sure if you are actually hitting this problem? The answer is BID tracing. I would not go into details of what is BID tracing and how to collect it. You can read about it </font><a href="https://msdn.microsoft.com/en-us/library/cc765421.aspx"><font size="2" face="Verdana">here</font></a><font size="2" face="Verdana">. All you need to trace is System.Data.SNI.1 and System.Data.1 from the application server. Here is a sample of what you will see in the trace:</font></p>

<div id="codeSnippetWrapper">
  <pre class="csharpcode">&lt;prov.DbConnectionHelper.ConnectionString_Set|API&gt; 1#, <span class="str">'Data <br />Source=MySQLServer;Failover Partner=MySQLServer2; Initial Catalog= <br />TestMirror;Integrated Security=SSPI;Connection Timeout=15'</span></pre>

  <pre class="csharpcode">enter_02 &lt;SNIReadSync|API|SNI&gt; 2#{SNI_Conn}, pConn: <br />007D9EA8{SNI_Conn*}, ppNewPacket: 0671E268{SNI_Packet**}, <font style="background-color: #ffff00"><font style="background-color: #ffff00"><strong>timeout: 1134</strong> </font><br /></font><br />enter_03 &lt;Np::ReadSync|API|SNI&gt; 3#, ppNewPacket: <br />0671E268{SNI_Packet**}, iTimeOut: 1134 <br /><br />&lt;SNI_Packet::SNIPacketAllocateEx2|API|SNI&gt; pConn: 007D9EA8{SNI_Conn*}, <br />IOType: 0, consumer: 0 <br />&lt;SNI_Packet::SNIPacketNew|API|SNI&gt; pConn: 007D9EA8{SNI_Conn*}, IOType: 0 <br />ObtainIDa 5# &lt;SNI_Packet::SNI_Packet|ID|SNI&gt; 0624EEF0{.} <br /><br />&lt;SNI_Packet::SNI_Packet|SNI&gt; 5#{SNI_Packet} created by 2#{SNI_Conn} <br /><br />&lt;SNI_Packet::SNIPacketNew|RET|SNI&gt; 0624EEF0{SNI_Packet*} <br /><br />&lt;SNI_Packet::SNIPacketAllocateEx2|RET|SNI&gt; 0624EEF0{SNI_Packet*} <br /><br />&lt;Np::ReadSync|ERR|SNI&gt; ProviderNum: 4{ProviderNum}, SNIError: <br />11{SNIError}, NativeError: 258{WINERR} <br />&lt;Np::ReadSync|RET|SNI&gt; 258{WINERR} <br />leave_03 <br />&lt;SNIReadSync|RET|SNI&gt; 258{WINERR}, Packet: 00000000 <br />leave_02 <br />&lt;sc.SqlError.SqlError|ERR&gt; infoNumber=-2, <br />errorState=0, errorClass=11, errorMessage=<span class="str">'Timeout expired. The timeout period <br />elapsed prior to completion of the operation or the server is not responding.'</span>, <br />procedure=<span class="str">''</span>, lineNumber=0 <br /><br />&lt;sc.SqlInternalConnectionTds.BreakConnection|RES|CPOOL&gt; 4#, Breaking connection. <br /><br />&lt;prov.DbConnectionInternal.<font style="background-color: #ffff00"><strong>DoomThisConnection</strong></font>|RES|INFO|CPOOL&gt; 4#, Dooming <br />&lt;sc.SqlInternalConnectionTds.LoginFailure|RES|CPOOL&gt; 4#</pre>
</div>

<p><font size="2" face="Courier New"></font></p>

<p><font size="2" face="Verdana"><strong>When Connection Timeout=15 sec (default value), actual Connection Timeout calculated= .08*15 ~ 1.2 sec</strong></font></p>

<p><font size="2" face="Verdana">From the trace you can see the SNIReadSync is setting the timeout to 1134 milliseconds. This is close to 1.2 seconds and when the server does not respond back within that time, it incorrectly dooms the connection. Truly speaking you do not actually need a mirrored database for this. All you need to mention is &quot;Failover Partner&quot; in your connection string. That is enough to take this connection retry algorithm code path.</font></p>

<p><font size="2" face="Verdana">While this problem should be fixed in Visual Studio 2011, there a few workarounds that can easily avoid this.</font></p>

<p><font size="2" face="Verdana">1. You can increase the connection string timeout to 150 sec. This will give the first attempt of SniReadSync enough time to connect (150* .08=12 sec)</font></p>

<p><font size="2" face="Verdana">2. Add &quot;Min Pool Size=20&quot; in the connection string. This will always maintain a minimum of 20 connections in the pool and there will be less need of creating new connection, thus reducing the chance of this error.</font></p>

<p><font size="2" face="Verdana">3. Improve the network performance. Most of these issues can be a result of a slow network. Update your NIC drivers to the latest firmware version. We have seen network latency when your NIC card is not compatible with certain </font><a href="https://support.microsoft.com/kb/912222"><font size="2" face="Verdana">Scalable Networking Pack</font></a><font size="2" face="Verdana"> settings, most commonly the TCP Chimney offload and the Receive Side Scaling(RSS) . If you are on Windows Vista SP1 or above you may also consider disabling </font><a href="https://support.microsoft.com/kb/947239"><font size="2" face="Verdana">Receive Window Auto-Tuning</font></a><font size="2" face="Verdana">. If you have NIC teaming enabled, disabling it would be a good option.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Testing SQL Connectivity with Machine Account</title>
      <link>https://docs.microsoft.com/archive/blogs/dipanb/testing-sql-connectivity-with-machine-account</link>
      <pubDate>Mon, 07 Mar 2011 09:50:00 GMT</pubDate>
      <dc:creator><![CDATA[Dipanjan Banik]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dipanb/2011/03/07/testing-sql-connectivity-with-machine-account/</guid>
      <description><![CDATA[Many times during troubleshooting SQL Server Connectivity, we face the challenge to test our...]]></description>
      <content:encoded><![CDATA[<p><font size="2" face="Verdana">Many times during troubleshooting SQL Server Connectivity, we face the challenge to test our connectivity with the Machine accounts. For instance say you have a service running under local system or network service account and that makes a connection to SQL Server. In such scenario it will connect in the context of Machine Account. In a Profiler, you will see the account name as Machine\SYSTEM in a local scenario or Domain\Machine$ in a remote connection.</font></p>  <p><font size="2" face="Verdana">I have many times faced issues where a regular domain user is able to successfully connect to SQL Server but any application running under the built in accounts are failing.</font></p>  <p><font size="2" face="Verdana">Testing connectivity with these accounts had always been challenging. In the past I used the AT command to schedule a windows task to launch a command in interactive mode. This launches cmd.exe under the SYSTEM account. Then I can test the SQL connectivity from here using osql or odbcad32.exe</font></p>  <p><a href="https://support.microsoft.com/kb/313565"><font size="2" face="Verdana">https://support.microsoft.com/kb/313565</font></a></p>  <p><font size="2" face="Verdana">This worked fine with Windows 2003 Server or Windows XP. But starting from Vista and higher, the AT command does not launch the task in interactive mode due to security reasons.</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/5025.clip_image001_30A9F62E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/5025.clip_5F00_image001_5F00_30A9F62E.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image001" border="0" alt="clip_image001" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/1200.clip_image001_thumb_1E317FAC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/1200.clip_5F00_image001_5F00_thumb_5F00_1E317FAC.png" width="540" height="143" /></a></p>  <p><font size="2" face="Verdana">The alternative I found was to use the PSExec Tool from SysInternals.</font></p>  <p><font size="2" face="Verdana">Run a cmd from PsExec tool and the command will launch under the SYSTEM account.</font></p>  <p><a href="https://technet.microsoft.com/en-US/sysinternals/bb897553.aspx"><font size="2" face="Verdana">https://technet.microsoft.com/en-US/sysinternals/bb897553.aspx</font></a></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/2474.clip_image002_122F8F78.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/2474.clip_5F00_image002_5F00_122F8F78.png"><font size="2" face="Verdana"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/0310.clip_image002_thumb_434ECA18.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/0310.clip_5F00_image002_5F00_thumb_5F00_434ECA18.png" width="533" height="203" /></font></a></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/4861.clip_image003_225B5771.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/4861.clip_5F00_image003_5F00_225B5771.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image003" border="0" alt="clip_image003" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/3377.clip_image003_thumb_73959ECE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-38-57-metablogapi/3377.clip_5F00_image003_5F00_thumb_5F00_73959ECE.png" width="532" height="235" /></a></p>]]></content:encoded>
    </item>
    <item>
      <title>“SSPI handshake failed” could result when the security event log has reached the maximum log size</title>
      <link>https://docs.microsoft.com/archive/blogs/dipanb/sspi-handshake-failed-could-result-when-the-security-event-log-has-reached-the-maximum-log-size</link>
      <pubDate>Wed, 08 Dec 2010 16:53:00 GMT</pubDate>
      <dc:creator><![CDATA[Dipanjan Banik]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dipanb/2010/12/08/sspi-handshake-failed-could-result-when-the-security-event-log-has-reached-the-maximum-log-size/</guid>
      <description><![CDATA[I see a lot of issues related to SQL Server connectivity. One common error I see in the SQL Server...]]></description>
      <content:encoded><![CDATA[<p><font color="#0000ff" size="2" face="Verdana">I see a lot of issues related to SQL Server connectivity. One common error I see in the SQL Server logs is the SSPI error. </font></p>  <div id="codeSnippetWrapper" class="csharpcode-wrapper">   <div id="codeSnippet" class="csharpcode">     <p>Logon Error: 17806, Severity: 20, State: 2.        <br />Logon SSPI handshake failed with error code 0x8009030c while establishing a connection with integrated security; the connection has been closed. [CLIENT:192.168.0.5]         <br />Logon Error: 18452, Severity: 14, State: 1.         <br />Logon Login failed for user ''. The user is not associated with a trusted SQL Server connection. [CLIENT:192.168.0.5]</p>      <p><font color="#0000ff" size="2" face="Verdana">We normally see two kinds of SSPI errors. One is “Cannot generate SSPI context” and the other is “SSPI Handshake Failed”. T</font><font color="#0000ff" size="2" face="Verdana">he first error is commonly because the client is trying a Kerberos authentication and that failed, </font><font color="#0000ff" size="2" face="Verdana">but it did not fall back to NTLM. The second one happens usually when the user is not authenticated. </font><font color="#0000ff" size="2" face="Verdana">So I looked into the SQL Server Security Event Logs and I can see this entry: </font></p>   </div> </div>  <pre class="csharpcode">Log Name: Security 
Source: Microsoft-Windows-Security-Auditing 
Date: 1/15/2011 2:52:01 PM 
Event ID: 4625 
Task Category: Logon 
Level: Information 
Keywords: Audit Failure 
User: N/A 
Computer: SQLMACHINE.corp.mydomain.com 
Description: 
An account failed to log on. 
Subject: 
Security ID: NULL SID 
Account Name: - 
Account Domain: - 
Logon ID: 0x0 
Logon Type: 3 
Account For Which Logon Failed: 
Security ID: NULL SID 
Account Name: APPSERVER$ 
Account Domain: CORP.MYDOMAIN.COM 
Failure Information: 
Failure Reason: Unknown user name or bad password. 
<font style="background-color: #ffff00">Status: 0xc000006e</font> 
Sub Status: 0x0 
Process Information: 
Caller Process ID: 0x0 
Caller Process Name: - 
Network Information: 
Workstation Name: - 
Source Network Address: - 
Source Port: - 
Detailed Authentication Information: 
Logon Process: Kerberos 
Authentication Package: Kerberos 
Transited Services: - 
Package Name (NTLM only): - 
Key Length: 0</pre>


<p><font color="#0000ff" size="2" face="Verdana">In this scenario, the app was trying to connect with the machine account. Typically when using windows authentication, if the application is running in the context of Local System or Network Service, the application will connect using the machine account. If you take a Profiler trace, the account name is shown as MachineName$.&#160; <br />If we add the APPSERVER$ account to the Administrators group of the SQL Server machine, we don’t see the problem. 

    <br />Looking into this error code: </font></p>

<pre class="csharpcode">err 0xc000006e 
# for hex 0xc000006e / decimal -1073741714 
<font style="background-color: #ffff00">STATUS_ACCOUNT_RESTRICTION</font> ntstatus.h 
# Indicates a referenced user name and authentication 
# information are valid, but some user account restriction 
# has prevented successful authentication (such as 
# time-of-day restrictions). </pre>


<p><font color="#0000ff" size="2" face="Verdana">Here, 0xc000006e means STATUS_ACCOUNT_RESTRICTION, which indicates referenced user name and authentication information are valid, but some user account restriction has prevented successful authentication. If we add that user account to the local Administrators group, we are able to connect to SQL Server. We believe it is because we have “Audit: Shutdown system immediately if unable to log security audits” policy enabled. If HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\CrashOnAuditFail is 1, the local policy “Audit: Shut down system immediately if unable to log security audits” is enabled. When the security logs become full, the CrashOnAuditFail value will be changed to 2. At this point, only local administrators can logon and non-administrator accounts will fail. </font></p>

<p><font color="#0000ff" size="2" face="Verdana">We checked HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\CrashOnAuditFail and the value was 2 
    <br />This problem occurs if the security event log has reached the maximum log size and the Event Log Wrapping setting is set to Overwrite Events Older than X Days or Do Not Overwrite Events. Because the security event log is full, and the CrashOnAuditFail registry key is set, Microsoft Windows does not permit accounts that are not administrator accounts to log on. </font></p>

<p><font color="#0000ff" size="2" face="Verdana">If the machine is a Web Server you may also see websites with anonymous access are being affected. When anonymous access is configured, requests to the Web site try to authenticate by using the IUSR_computername and IWAM_computername accounts. These accounts are not administrator accounts. </font></p>

<p><font color="#0000ff" size="2" face="Verdana">For further details please refer the following KB <a href="https://support.microsoft.com/kb/832981">832981</a> 

    <br /></font></p>

<p><font color="#0000ff" size="2" face="Verdana"></font></p>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server Query Performance when running query from a Windows 2008 Server</title>
      <link>https://docs.microsoft.com/archive/blogs/dipanb/sql-server-query-performance-when-running-query-from-a-windows-2008-server</link>
      <pubDate>Wed, 09 Jun 2010 10:20:00 GMT</pubDate>
      <dc:creator><![CDATA[Dipanjan Banik]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dipanb/2010/06/09/sql-server-query-performance-when-running-query-from-a-windows-2008-server/</guid>
      <description><![CDATA[Recently I faced two cases in which we can see slow query performance when we run a SQL Server query...]]></description>
      <content:encoded><![CDATA[<p><span style="color: #0000ff"><span style="font-size: small">Recently I faced two cases in which we can see slow query performance when we run a SQL Server query from a Windows Server 2008 client machine. The query takes more time to complete when we run it from a Win2K8 machine as compared to a Win2K3 or WinXP machine. To test this we opened a SQLCMD.exe from the SQL Server 2008 machine and ran the following command:</span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">&nbsp;</span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small">Microsoft Windows [Version 6.1.7600] <br />Copyright (c) 2009 Microsoft Corporation.&nbsp; All rights reserved. </span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">C:\Users\dipanb&gt;cd \Program Files\Microsoft SQL Server\100\Tools\Binn </span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">C:\Program Files\Microsoft SQL Server\100\Tools\Binn&gt;sqlcmd -S GODFATHER1 -U testuser -P testuser -l 5 -Q"select 1" <br />HResult 0x102, Level 16, State 1 <br />TCP Provider: Timeout error [258]. <br />Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Unable to complete login process due to delay in login response. <br />Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Login timeout expired. </span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">C:\Program Files\Microsoft SQL Server\100\Tools\Binn&gt;</span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">&nbsp;</span></span></span><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">As we can see if I reduce the connect timeout to 5 sec, we get a connection timeout. From a good client machine running on W2K3 Server or WinXp, if I set the timeout to 1 sec, I am still able to make a successful connection and I get a row returned. So what is different in the Windows 2008 Server machine? To find out what is happening, I took a Network trace using </span></span></span><a href="https://www.microsoft.com/downloads/details.aspx?FamilyID=983b941d-06cb-4658-b7f6-3088333d062f&amp;displaylang=en"><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">Microsoft Network Monitor 3.3</span></span></span></a></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/0552.Capture_6E40357C.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-57-metablogapi/0552.Capture_5F00_6E40357C.jpg"><span style="font-size: small"><span style="font-size: small;"><img height="349" width="700" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/4237.Capture_thumb_1F4F4A50.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-57-metablogapi/4237.Capture_5F00_thumb_5F00_1F4F4A50.jpg" alt="Capture" border="0" title="Capture" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" /></span></span></a><span style="font-size: small"><span style="font-size: small;"> </span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small">We can see a delay of approx 5 seconds in the trace. This tells us why we were getting a timeout if we reduced the connect timeout to 5 secs because the delay happened before the pre-login handshake.</span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">The other customer facing this same issue was running a Linked Server query. </span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">In this example, the Linked Server was on a Windows 2008 Server running from a SQL Server 2008 Sp1. It was querying a SQL Server 2005 running on Windows Server 2003. When I run the query through the Linked Server, it was taking 55 secs to return 64 rows. If I run the query directly from the 2005 SQL Server, the result is instantaneous. To troubleshoot this I took a Network trace from the Primary Server where the Linked Server is located and also on the Destination Server, from where the Linked Server is pulling data. </span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"></span></span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/4667.Capture1_78CD1B6A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-57-metablogapi/4667.Capture1_5F00_78CD1B6A.jpg"><span style="font-size: small"><span style="font-size: small;"><img height="673" width="654" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/8080.Capture1_thumb_6F148767.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-57-metablogapi/8080.Capture1_5F00_thumb_5F00_6F148767.jpg" alt="Capture1" border="0" title="Capture1" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" /></span></span></a><span style="font-size: small"><span style="font-size: small;"> </span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small">We are seeing the same 5 sec delay here as well. </span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><strong><span style="font-size: small;">Resolution</span></strong></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">This delay may happen when your NIC Card or a router is not compatible with a few features which I am describing below:</span></span></span></p>
<p><span style="font-size: small;"><span style="color: #0000ff;">The Scalable Networking Pack (SNP) feature includes TCP Chimney Offloading, Receive Side Scaling (RSS) and Network Direct Memory Access (NetDMA). For a Windows 2008 Server, TCP Chimney is disabled but RSS and NetDMA are enabled by default. The other factor which may contribute to the delay is </span><span style="color: #0000ff;">Receive Window Auto Tuning feature which was introduced since Windows Vista SP1. </span></span></p>
<p><span style="font-size: small"><span style="color: #0000ff;"><span style="font-size: small;">It is recommended to follow up with your network adapter vendor to see if they have an updated driver that will address the problem and allow the use of the above features. As an immediate relief you may turn these features off.</span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">1. Receive side scaling <strong><span style="color: #ff0000;">(netsh int tcp set global rss=disabled)</span></strong> This was causing 15 sec latency.</span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">2. Autotuning level <span style="color: #ff0000;"><strong>(netsh interface tcp set global autotuninglevel=disabled)</strong></span> This was causing 52 seconds latency.</span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">You can run the following command to get the TCP IP global values <br /><strong><span style="color: #ff0000;">netsh int tcp show global</span></strong> </span></span></span></p>
<p><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">After you disable the above settings your tcp global values should look like this:</span></span></span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/6648.image_71E9A080.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-57-metablogapi/6648.image_5F00_71E9A080.png"><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;"><img height="388" width="707" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/38/57/metablogapi/4520.image_thumb_67D4FF55.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-38-57-metablogapi/4520.image_5F00_thumb_5F00_67D4FF55.png" alt="image" border="0" title="image" style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" /></span></span></span></a><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;"> </span></span></span></p>
<p><span style="font-family: ; color: #ff0000"><strong><span style="font-size: small">Note: You may not see this behavior on all Windows 2008 Server when we have these values turned on. These happens only if you have an old router or NIC card and they are not compatible with these settings turned on.</span></strong></span></p>
<h4><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">More Information</span></span></span></h4>
<h4><a href="https://support.microsoft.com/kb/951037" title="https://support.microsoft.com/kb/951037"><span style="font-size: small;">https://support.microsoft.com/kb/951037</span></a></h4>
<p><a href="https://support.microsoft.com/kb/947239"><span style="color: #0000ff"><span style="font-size: small"><span style="font-size: small;">https://support.microsoft.com/kb/947239</span></span></span></a></p>
<p><span style="font-family: ; color: #0000ff"></span></p>]]></content:encoded>
    </item>
  </channel>
</rss>