<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Tianxiang Chen's Tech Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/tiche/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/tiche/feed.xml</link>
    <description>Readability counts.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:43:06 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>WCF on intranet with windows authentication: Kerberos or NTLM (Part 1)</title>
      <link>https://docs.microsoft.com/archive/blogs/tiche/wcf-on-intranet-with-windows-authentication-kerberos-or-ntlm-part-1</link>
      <pubDate>Tue, 12 Jul 2011 21:10:35 GMT</pubDate>
      <dc:creator><![CDATA[tiche MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/tiche/2011/07/12/wcf-on-intranet-with-windows-authentication-kerberos-or-ntlm-part-1/</guid>
      <description><![CDATA[The issue  When we build enterprise level SOA system on top of windows servers, if the environment...]]></description>
      <content:encoded><![CDATA[<h2>The issue</h2>  <p>When we build enterprise level SOA system on top of windows servers, if the environment is with Active Directory, using windows authentication is probably the most appropriate authentication mechanism which is secure, straight forward to build and easy to maintain. Underneath WCF's windows authentication implementation, two SSP are used: <a href="http://msdn.microsoft.com/en-us/library/aa480609.aspx" target="_blank">Kerberos</a> and <a href="http://msdn.microsoft.com/en-us/library/aa378749(v=vs.85).aspx" target="_blank">NTLM</a>. You might encounter the same issues like I did, here I want to share some of the experience come from my trouble shooting.</p>  <p>If we use domain user to host a WCF service, and call this service from another machine, very likely we will have this error:</p>  <blockquote>   <p><strong>A call to SSPI failed</strong>, see inner exception. ---&gt; System.ComponentModel.Win32Exception: <strong>The target principal name is incorrect</strong></p> </blockquote>  <p>There are quite a lot articles (<a href="http://mastermynd-code.blogspot.com/2009/06/service-principal-name-when-using-wcf.html" target="_blank">1</a>, <a href="http://marbie.wordpress.com/2008/05/30/kerberos-delegation-and-service-identity-in-wcf/" target="_blank">2</a>, <a href="http://offroadcoder.com/2009/10/29/NetTcpBindingAndSecurityNegotiationExceptionACallToSSPIFailed.aspx" target="_blank">3</a>, <a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/90ab4603-804a-43a1-a703-c0fb6a12ee41/" target="_blank">4</a>) discussing this issue, basically their solution is to: </p>  <ol>   <li>use setspn.exe to create an SPN for the domain account </li>    <li>configure at client side, set spn as client identity</li> </ol>  <p>However, the odd thing is actually we can skip step 1, and set a dummy string in step 2, it also works. Why? I am not the first one who has this question, these 2 posts (<a href="http://whycanfail.wordpress.com/2008/07/17/error-the-target-principal-name-is-incorrect/" target="_blank">1</a>, <a href="http://chrisoldwood.blogspot.com/2010/02/wcf-weirdy-nettcpbinding.html" target="_blank">2</a>) has the exact same question against this. So, I decided to dig deeper and find the root cause.</p>  <h2>Analysis</h2>  <p>From the result of the workaround, we can 'feel' that the key point is which protocol is used in authentication, NTLM or Kerberos, they make the difference. This KB tells us how WCF choose the protocol, as below (left column is client / top row is server):</p>  <table border="0" cellspacing="0" cellpadding="2" width="760"><tbody>     <tr>       <td valign="top" width="152">&nbsp;</td>        <td valign="top" width="157">         <p>Local User</td></p>       </td>        <td valign="top" width="152">         <p>Local System</td></p>       </td>        <td valign="top" width="149">         <p>Domain User</td></p>       </td>        <td valign="top" width="148">         <p>Domain Machine</td></p>       </td>     </tr>      <tr>       <td valign="top" width="152">         <p>Local User</td></p>       </td>        <td valign="top" width="157">         <p>NTLM</td></p>       </td>        <td valign="top" width="152">         <p>NTLM</td></p>       </td>        <td valign="top" width="149">         <p>NTLM</td></p>       </td>        <td valign="top" width="148">         <p>NTLM</td></p>       </td>     </tr>      <tr>       <td valign="top" width="152">         <p>Local System</td></p>       </td>        <td valign="top" width="157">         <p>Anonymous NTLM</td></p>       </td>        <td valign="top" width="152">         <p>Anonymous NTLM</td></p>       </td>        <td valign="top" width="149">         <p>Anonymous NTLM</td></p>       </td>        <td valign="top" width="148">         <p>Anonymous NTLM</td></p>       </td>     </tr>      <tr>       <td valign="top" width="152">         <p>Domain User</td></p>       </td>        <td valign="top" width="157">         <p>NTLM</td></p>       </td>        <td valign="top" width="152">         <p>NTLM</td></p>       </td>        <td valign="top" width="149">         <p>Kerberos</td></p>       </td>        <td valign="top" width="148">         <p>Kerberos</td></p>       </td>     </tr>      <tr>       <td valign="top" width="152">         <p>Domain Machine</td></p>       </td>        <td valign="top" width="157">         <p>NTLM</td></p>       </td>        <td valign="top" width="152">         <p>NTLM</td></p>       </td>        <td valign="top" width="149">         <p>Kerberos</p>       </td>        <td valign="top" width="148">         <p>Kerberos</p>       </td>     </tr>   </tbody></table>  <p>In our case, we are using domain user and domain machine (network service cross machine), they should all use Kerberos as 1st choice.</p>  <p>How do we know which protocol is finally picked? There are two ways:</p>  <ol>   <li>Look at the Security Event Log, you can filter like I do:     <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/2625.image_2E211832.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/2625.image_5F00_2E211832.png"><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="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/4846.image_thumb_045D9D3F.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/4846.image_5F00_thumb_5F00_045D9D3F.png" width="818" height="160" /></a>      <br />View the 'Logon' event, it can tell us Kerberos or NTLM:      <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/1122.image_4FDCCAF6.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/1122.image_5F00_4FDCCAF6.png"><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="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/0243.image_thumb_6794025C.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/0243.image_5F00_thumb_5F00_6794025C.png" width="433" height="220" /></a>      <br /><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/7573.image_77BFCA55.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/7573.image_5F00_77BFCA55.png"><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="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/0537.image_thumb_649E9DA9.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/0537.image_5F00_thumb_5F00_649E9DA9.png" width="435" height="178" /></a></li>    <li>Disable NTLM at client side and call service.      <br />We can configure this at code level:      <br />      <div id="codeSnippetWrapper">       <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; 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">         <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum1">   1:</span> channelFactory = <span style="color: #0000ff">new</span> ChannelFactory&lt;TChannel&gt;(binding);</pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum2">   2:</span> channelFactory.Credentials.Windows.AllowNtlm = allowNTLM;</pre>
<!--CRLF--></div>
    </div>
Or in config file:

    <div id="codeSnippetWrapper">
      <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; 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">
        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">behaviors</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum2">   2:</span>       <span style="color: #0000ff">&lt;</span><span style="color: #800000">endpointBehaviors</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum3">   3:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">behavior</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;WcfTestBehavior&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum4">   4:</span>           <span style="color: #0000ff">&lt;</span><span style="color: #800000">clientCredentials</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum5">   5:</span>             <span style="color: #0000ff">&lt;</span><span style="color: #800000">windows</span> <span style="color: #ff0000">allowNtlm</span><span style="color: #0000ff">=&quot;<font style="background-color: #ffff00">false</font>&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum6">   6:</span>           <span style="color: #0000ff">&lt;/</span><span style="color: #800000">clientCredentials</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum7">   7:</span>         <span style="color: #0000ff">&lt;/</span><span style="color: #800000">behavior</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum8">   8:</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">endpointBehaviors</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum9">   9:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">behaviors</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum10">  10:</span>   <span style="color: #0000ff">&lt;/</span><span style="color: #800000">system.serviceModel</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
    </div>
If NTLM is picked and we disable that, we will get this exception:

    <br /><strong>System.ServiceModel.Security.SecurityNegotiationException:The remote server did not satisfy the mutual authentication requirement.</strong></li>
</ol>

<p>Now we are ready to do the experiment to see the logic inside WCF. </p>

<p>As I said before, this &quot;A call to SSPI failed&quot; exception only occurs when service is run under domain account, and client is from another machine. So If we put the client to the same machine of the server side, it can succeed, that's because it is using NTLM. This behavior is expected from the information in the protocol choosing strategy table.</p>

<p>If we set the dummy string as the SPN in client side, we can see it actually use the NTLM to authenticate. Why it cannot fallback to NTLM if we don't specify the spn?</p>

<p>I tried to dig out the reason via reflector, however unfortunately I failed to get 100% correct answer because I found myself not able to understand the fancy WCF design, too many factories, base classes, reflections, etc, just dizzy<img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="微笑" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/5824.wlEmoticon-smile_74CA65A2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/5824.wlEmoticon_2D00_smile_5F00_74CA65A2.png" /></p>

<p>Per my experiment, my assumption is: if identity is not specified on client side, it would automatically create identity using the hostname in the Uri, suppose we are calling <strong>net.tcp://remotemachine1:port/MyService</strong>, the WCF client will use the machine name as spn, that is: <strong>EndpointIdentity.CreateSpnIdentity(&quot;remotemachine1&quot;)</strong> to call service. 

  <br />The tricky logic is: if the SPN specified in client is valid, WCF would use this to do Kerberos auth. If SPN is not a correct one, it would pick NTLM. That's why it is working if we specify any dummy string as SPN, it is actually fallback to NTLM because the SPN is invalid.

  <br />This is not cool and correct to me, because the logic is not like Negotiate, described in this <a href="http://msdn.microsoft.com/en-us/library/aa378749(v=vs.85).aspx" target="_blank">document</a>:</p>

<blockquote>
  <p>Your application should not access the NTLM security package directly; instead, it should use the <a href="http://msdn.microsoft.com/en-us/library/ms721596(v=vs.85).aspx#_security_negotiate_gly"><em>Negotiate</em></a> security package. Negotiate allows your application to take advantage of more advanced <a href="http://msdn.microsoft.com/en-us/library/ms721625(v=vs.85).aspx#_security_security_protocol_gly"><em>security protocols</em></a> if they are supported by the systems involved in the authentication. Currently, the Negotiate security package selects between <a href="http://msdn.microsoft.com/en-us/library/ms721590(v=vs.85).aspx#_security_kerberos_protocol_gly"><em>Kerberos</em></a> and NTLM. Negotiate selects Kerberos unless it cannot be used by one of the systems involved in the authentication.</p>
</blockquote>

<p>The WCF's fallback logic is crappy, waste thousands of poor .net developer huge amount of time to investigate the failure and workaround. If it can use this logic: &quot;try Kerberos, if fail, try NTLM&quot;, I bet very few people would even see this ugly SSPI exception.</p>

<p>To make it clear, I drew a diagram to illustrate the logic (I don't guarantee 100% of correctness):</p>

<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/4747.image_3B4755AB.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/4747.image_5F00_3B4755AB.png"><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="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/0121.image_thumb_001379E0.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/0121.image_5F00_thumb_5F00_001379E0.png" width="703" height="656" /></a></p>











<h2>Solutions</h2>

<p>Now we know the fact that we are actually using NTLM to workaround the issue in the most cases. </p>

<p>If you don't care Kerberos and NTLM,&#160; you can use <strong>String.Empty or null</strong> to create SPN identity at client side, you always go to NTLM.</p>

<p>What if we want to stick to Kerberos, what should we do?</p>

<p>We got original exception &quot;A call to SSPI failed&quot; because the remote service account (domain account) has no access to the machine SPN key, but if we use &quot;Network service&quot; or &quot;Local system&quot; to run the server side, they have the access so the Kerberos auth can be done. </p>

<p>The arbitrary SPN's syntax is &lt;ServiceClass&gt;/&lt;ServiceName&gt;, the machine SPN = HOST/MACHINENAME, we can use <strong>setspn.exe –L machinename$</strong> to see the set of SPNs that machine account has.</p>

<p>So, can we create a SPN for the service account, using the HOST/MACHINENAME, so that client side would need no change?</p>

<blockquote>
  <p><strike>setspn.exe –U –A HOST/SERVERNAME DOMAIN\SERVICEACCOUNT</strike></p>
</blockquote>

<p>Unfortunately the answer is NO. By doing this command, it would cause duplicate SPN record, and Kerberos would always fail. </p>

<p>To check duplicate SPNs, use <strong>setspn.exe –X</strong></p>

<p>We have to use a different name to create the SPN for the user, for example: MySystem/Service1. </p>

<blockquote>
  <p>setspn.exe –U –A MySystem/Service1 DOMAIN\SERVICEACCOUNT</p>
</blockquote>

<p>Then we come back to client side, set the identity:</p>

<ol>
  <li>in config file, set inside the endpoint node:
    <br />

    <div id="codeSnippetWrapper">
      <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; 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">
        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">endpoint</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;winservicenettcp&quot;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum2">   2:</span>                 <span style="color: #ff0000">binding</span><span style="color: #0000ff">=&quot;netTcpBinding&quot;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum3">   3:</span>                 <span style="color: #ff0000">bindingConfiguration</span><span style="color: #0000ff">=&quot;netTcp&quot;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum4">   4:</span>                 <span style="color: #ff0000">address</span><span style="color: #0000ff">=&quot;net.tcp://myserver:12345/WcfPerfTest&quot;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum5">   5:</span>                 <span style="color: #ff0000">contract</span><span style="color: #0000ff">=&quot;Contract.IPerfTest&quot;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum6">   6:</span>                 <span style="color: #ff0000">behaviorConfiguration</span><span style="color: #0000ff">=&quot;WcfTestBehavior&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum7">   7:</span>         <span style="color: #0000ff">&lt;</span><span style="color: #800000">identity</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum8">   8:</span>           <span style="color: #0000ff">&lt;</span><span style="color: #800000">servicePrincipalName</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;MySystem/Service1&quot;</span><span style="color: #0000ff">/&gt;</span>          </pre>
<!--CRLF-->

        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum9">   9:</span>         <span style="color: #0000ff">&lt;/</span><span style="color: #800000">identity</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF-->

        <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"><span style="color: #606060" id="lnum10">  10:</span>       <span style="color: #0000ff">&lt;/</span><span style="color: #800000">endpoint</span><span style="color: #0000ff">&gt;</span></pre>
<!--CRLF--></div>
    </div>
  </li>

  <li>Or in code level, set in EndpointAdress:
    <br />

    <div id="codeSnippetWrapper">
      <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; 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">
        <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; 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"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">new</span> EndpointAddress(<span style="color: #0000ff">new</span> Uri(ServiceUrl), EndpointIdentity.CreateSpnIdentity(<span style="color: #006080">&quot;MySystem/Service1&quot;</span>));</pre>
<!--CRLF--></div>
    </div>
  </li>
</ol>



<p>If we didn't create SPN successfully, it could still pass because it can fallback to NTLM, so we can disable NTLM at client side.</p>

<p>Another solution is use <a href="http://msdn.microsoft.com/en-us/library/ms733130.aspx" target="_blank">UPN</a>, in config it is userPrincipalName and in code it is EndpointIdentity.CreateUpnIdentity. Just use the service account's upn (mydomain\accountname) as input, and it can also succeed.</p>

<p>Another useful tool in debugging Kerberos is <strong>klist.exe</strong>. It can show use the current cached KerbTicket in the system, make sure you run <strong>klist.exe purge</strong> after we change something, or the cached ticket would give us some bogus result.</p>

<h2>Conclusion</h2>

<p>Because of the weird design of WCF windows authentication, it is very challenging to write a generic client wrapper because you cannot tell how to set identity (not set, use correct spn, use correct upn or use dummy spn) just from the Uri. Personally I would say the behavior is a bug, if it is by design, it must be a very bad design<img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="微笑" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/5824.wlEmoticon-smile_74CA65A2.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-22-58-metablogapi/5824.wlEmoticon_2D00_smile_5F00_74CA65A2.png" /> If it can change to &quot;Kerberos first, if fail, try NTLM&quot;, that would be fantastic, although seems not very possible ^_^</p>]]></content:encoded>
    </item>
    <item>
      <title>test syntax</title>
      <link>https://docs.microsoft.com/archive/blogs/tiche/test-syntax</link>
      <pubDate>Wed, 22 Jun 2011 23:15:00 GMT</pubDate>
      <dc:creator><![CDATA[tiche MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/tiche/2011/06/22/test-syntax/</guid>
      <description><![CDATA[select * from web
&nbsp;
public class AA{ }
&nbsp;
public class AA{ }]]></description>
      <content:encoded><![CDATA[<pre class="scroll"><code class="mysql">select * from web</code></pre>
<pre class="scroll"><code class="mysql"></code>&nbsp;</pre>
<pre class="scroll"><code class="csharp">public class AA{<br /> }</code></pre>
<pre class="scroll"><code class="csharp"></code>&nbsp;</pre>
<pre class="scroll"><code class="csharp">public class AA{ }</code></pre>]]></content:encoded>
    </item>
    <item>
      <title>A simple database backup restore class based on ADO.net</title>
      <link>https://docs.microsoft.com/archive/blogs/tiche/a-simple-database-backup-restore-class-based-on-ado-net</link>
      <pubDate>Mon, 14 Feb 2011 02:04:00 GMT</pubDate>
      <dc:creator><![CDATA[tiche MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/tiche/2011/02/14/a-simple-database-backup-restore-class-based-on-ado-net/</guid>
      <description><![CDATA[During development/testing, to backup/restore database is a common task. Manual clicks are not ideal...]]></description>
      <content:encoded><![CDATA[<p>During development/testing, to backup/restore database is a common task. Manual clicks are not ideal solution, to automation, commonly we have two solutions:</p>
<ol>
<li>Leverage database server feature, such as SQLServer backup/restore, which is database level.</li>
<li>Backup/Restore in table level, store it in file.</li>
</ol>
<p>Neither of them is perfect:</p>
<table border="1">
<tbody>
<tr>
<td></td>
<td>Solution1:&nbsp; DB Level</td>
<td>Solution 2: Table Level</td>
</tr>
<tr>
<td>PROS</td>
<td>
<p>The feature is provided by product which should be stable.<br />Foreign key can be handled correctly and easily</p>
</td>
<td>Fine grained control, be able to skip some tables to get faster speed.<br />Easy to deal with Replication/Mirroring/Logshipping</td>
</tr>
<tr>
<td>CONS</td>
<td>Very difficult under multi-server environment. Such as Replication, Mirroring, etc.</td>
<td>If table has foreign key, the logic would be very complicated</td>
</tr>
</tbody>
</table>
<p>I am lucky that our new system adopts the foreign key free sql design, so solution 2 looks a good choice for us.</p>
<p>Here is a very simple class to do the back/restore job:</p>
<p>To enumerate table names:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', Courier, Monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> List&lt;<span style="color: #0000ff;">string</span>&gt; GetTableNames()</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span>     List&lt;<span style="color: #0000ff;">string</span>&gt; result = <span style="color: #0000ff;">new</span> List&lt;<span style="color: #0000ff;">string</span>&gt;();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span>     <span style="color: #0000ff;">string</span> tableName = <span style="color: #0000ff;">string</span>.Empty;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span>     <span style="color: #0000ff;">string</span> sql = <span style="color: #006080;">"SELECT name AS table_name, * FROM sys.tables WHERE Type = 'U'"</span>;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span>     <span style="color: #0000ff;">using</span> (SqlConnection conn = <span style="color: #0000ff;">new</span> SqlConnection(ConnectionString))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span>     <span style="color: #0000ff;">using</span> (DataTable table = <span style="color: #0000ff;">new</span> DataTable())</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span>     <span style="color: #0000ff;">using</span> (SqlDataAdapter adapter = <span style="color: #0000ff;">new</span> SqlDataAdapter(sql, conn))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span>     {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span>         adapter.Fill(table);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>         <span style="color: #0000ff;">foreach</span> (DataRow row <span style="color: #0000ff;">in</span> table.Rows)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span>         {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span>             result.Add(Convert.ToString(row[<span style="color: #006080;">"table_name"</span>]));</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span>         }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span>     }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span>     result.Sort();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span>     <span style="color: #0000ff;">return</span> result;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span> }</pre>
<!--CRLF--></div>
</div>
<p>To backup tables to DataSet/String:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', Courier, Monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #008000;">/// &lt;summary&gt;</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> <span style="color: #008000;">/// Pass null as includedTables if you want to backup all.</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span> <span style="color: #008000;">///     Actual tables = includedTables - excludedTables</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span> <span style="color: #008000;">/// &lt;/summary&gt;</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span> <span style="color: #0000ff;">public</span> DataSet BackupDatabase(List&lt;<span style="color: #0000ff;">string</span>&gt; includedTables = <span style="color: #0000ff;">null</span>, List&lt;<span style="color: #0000ff;">string</span>&gt; excludedTables = <span style="color: #0000ff;">null</span>)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span> {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span>     includedTables = includedTables ?? GetTableNames();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span>     <span style="color: #0000ff;">if</span> (excludedTables != <span style="color: #0000ff;">null</span>)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span>     {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span>         includedTables = includedTables.Except(excludedTables, StringComparer.OrdinalIgnoreCase).ToList();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>     }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span> &nbsp;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span>     DataSet result = <span style="color: #0000ff;">new</span> DataSet();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span>     <span style="color: #0000ff;">using</span> (SqlConnection conn = <span style="color: #0000ff;">new</span> SqlConnection(ConnectionString))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span>     {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span>         includedTables.ForEach(t =&gt;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span>             {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span>                 <span style="color: #0000ff;">string</span> sql = <span style="color: #006080;">"select * from "</span> + t;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;">  19:</span>                 <span style="color: #0000ff;">using</span> (SqlDataAdapter adapter = <span style="color: #0000ff;">new</span> SqlDataAdapter(sql, conn))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;">  20:</span>                 {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;">  21:</span>                     adapter.Fill(result, t);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;">  22:</span>                 }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;">  23:</span>             });</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;">  24:</span>     }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;">  25:</span>     <span style="color: #0000ff;">return</span> result;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;">  26:</span> }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;">  27:</span> &nbsp;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;">  28:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> BackupDatabaseToString(List&lt;<span style="color: #0000ff;">string</span>&gt; includedTables = <span style="color: #0000ff;">null</span>, List&lt;<span style="color: #0000ff;">string</span>&gt; excludedTables = <span style="color: #0000ff;">null</span>)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;">  29:</span> {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;">  30:</span>     <span style="color: #0000ff;">using</span> (var dataSet = BackupDatabase(includedTables, excludedTables))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;">  31:</span>     <span style="color: #0000ff;">using</span> (MemoryStream ms = <span style="color: #0000ff;">new</span> MemoryStream())</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;">  32:</span>     {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;">  33:</span>         dataSet.WriteXml(ms, XmlWriteMode.WriteSchema);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;">  34:</span>         <span style="color: #0000ff;">return</span> Encoding.UTF8.GetString(ms.ToArray());</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;">  35:</span>     }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum36" style="color: #606060;">  36:</span> }</pre>
<!--CRLF--></div>
</div>
<p>To restore table from DataSet:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', Courier, Monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum1" style="color: #606060;">   1:</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> RestoreDatabase(DataSet newDataSet)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum2" style="color: #606060;">   2:</span> {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum3" style="color: #606060;">   3:</span>     <span style="color: #0000ff;">using</span> (TransactionScope scope = <span style="color: #0000ff;">new</span> TransactionScope())</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum4" style="color: #606060;">   4:</span>     <span style="color: #0000ff;">using</span> (SqlConnection conn = <span style="color: #0000ff;">new</span> SqlConnection(ConnectionString))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum5" style="color: #606060;">   5:</span>     <span style="color: #0000ff;">using</span> (DataSet currentDataSet = <span style="color: #0000ff;">new</span> DataSet())</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum6" style="color: #606060;">   6:</span>     {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum7" style="color: #606060;">   7:</span>         conn.Open();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum8" style="color: #606060;">   8:</span>         <span style="color: #0000ff;">foreach</span> (DataTable newTable <span style="color: #0000ff;">in</span> newDataSet.Tables)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum9" style="color: #606060;">   9:</span>         {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum10" style="color: #606060;">  10:</span>             <span style="color: #0000ff;">string</span> tableName = newTable.TableName;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum11" style="color: #606060;">  11:</span>             SqlCommand deleteAllCmd = <span style="color: #0000ff;">new</span> SqlCommand(<span style="color: #006080;">"delete from "</span> + tableName, conn);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum12" style="color: #606060;">  12:</span>             deleteAllCmd.ExecuteNonQuery();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum13" style="color: #606060;">  13:</span>             <span style="color: #008000;">// reseed the indetity columns</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum14" style="color: #606060;">  14:</span>             SqlCommand reseedCmd = <span style="color: #0000ff;">new</span> SqlCommand(String.Format(<span style="color: #006080;">"DBCC CHECKIDENT ('{0}', RESEED, -1)"</span>, tableName), conn);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum15" style="color: #606060;">  15:</span>             <span style="color: #0000ff;">try</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum16" style="color: #606060;">  16:</span>             {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum17" style="color: #606060;">  17:</span>                 reseedCmd.ExecuteNonQuery();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum18" style="color: #606060;">  18:</span>             }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum19" style="color: #606060;">  19:</span>             <span style="color: #0000ff;">catch</span> { } <span style="color: #008000;">// ignore the error from table without identity columns</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum20" style="color: #606060;">  20:</span> &nbsp;</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum21" style="color: #606060;">  21:</span>             <span style="color: #0000ff;">using</span> (SqlDataAdapter adapter = <span style="color: #0000ff;">new</span> SqlDataAdapter(<span style="color: #006080;">"select * from "</span> + tableName, conn))</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum22" style="color: #606060;">  22:</span>             {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum23" style="color: #606060;">  23:</span>                 adapter.Fill(currentDataSet, tableName);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum24" style="color: #606060;">  24:</span>                 <span style="color: #0000ff;">foreach</span> (DataRow newRow <span style="color: #0000ff;">in</span> newTable.Rows)</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum25" style="color: #606060;">  25:</span>                 {</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum26" style="color: #606060;">  26:</span>                     currentDataSet.Tables[tableName].Rows.Add(newRow.ItemArray);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum27" style="color: #606060;">  27:</span>                 }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum28" style="color: #606060;">  28:</span>                 Console.WriteLine(<span style="color: #006080;">"restoring table '{0}' with {1} rows"</span>, tableName, newTable.Rows.Count);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum29" style="color: #606060;">  29:</span>                 SqlCommandBuilder dummyCmd = <span style="color: #0000ff;">new</span> SqlCommandBuilder(adapter); <span style="color: #008000;">// this would generate insertCommand inside adapter</span></pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum30" style="color: #606060;">  30:</span>                 adapter.Update(currentDataSet, tableName);</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum31" style="color: #606060;">  31:</span>             }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum32" style="color: #606060;">  32:</span>         }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum33" style="color: #606060;">  33:</span>         scope.Complete();</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum34" style="color: #606060;">  34:</span>     }</pre>
<!--CRLF-->
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', Courier, Monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span id="lnum35" style="color: #606060;">  35:</span> }</pre>
<!--CRLF--></div>
</div>
<p>You can use this in your c# automated test case, or powershell.</p>]]></content:encoded>
    </item>
    <item>
      <title>Xcopy deployment of Asp.Net Mvc 3</title>
      <link>https://docs.microsoft.com/archive/blogs/tiche/xcopy-deployment-of-asp-net-mvc-3</link>
      <pubDate>Sat, 08 Jan 2011 07:05:26 GMT</pubDate>
      <dc:creator><![CDATA[tiche MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/tiche/2011/01/08/xcopy-deployment-of-asp-net-mvc-3/</guid>
      <description><![CDATA[To be more precise, this entry is talking about how to deploy Asp.Net Mvc 3 web application without...]]></description>
      <content:encoded><![CDATA[<p>To be more precise, this entry is talking about how to deploy Asp.Net Mvc 3 web application without deploying the official 21MB installation pacakge.</p>  <p>Basically, to deploy an Mvc 3 web app is amazingly easy: we just need to install <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=955d593e-cbd1-4ed1-88eb-02ff79dd74d8&amp;displaylang=en" target="_blank">AspNetMVC3Setup.exe</a> on the web server, then use <a href="http://www.iis.net/download/webdeploy" target="_blank">MsDeploy</a>, or just copy the binary and content to the destination folder, that’s it.</p>  <p>However sometimes you want to make the automation of the deployment even easier and cleaner, or, you might not be able to install the MVC3 base package on your environment. No worry, it is not that difficult.</p>  <h3>Prerequisite</h3>  <ul>   <li>Windows Server 2008/R2 with IIS 7. </li>    <li>.Net 4.0 runtime is installed on the server. </li> </ul>  <p>.Net 4.0 is needed, since the Mvc 3 binaries are built from it, I haven’t tested whether it is possible to grab the code and build from .net 3.5.    <br />And I didn’t test IIS 6.</p>  <h3>To Deploy:</h3>  <p>Use the <a href="http://www.iis.net/download/webdeploy" target="_blank">MsDeploy</a>, then publish from visual studio, it would create the web application for you automatically.</p>  <p>Or, just manually create the web application, then copy the folder structure to your server. Here I use the default template of Mvc3 as an example, you need to include the *.cshtml (I use Razor), *.js, css, web.config and asax file.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/7418.image_1CDD3210.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-22-58-metablogapi/7418.image_5F00_1CDD3210.png"><img style="background-image: none; border-right-width: 0px; margin: 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="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/22/58/metablogapi/5857.image_thumb_781BF4CB.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-22-58-metablogapi/5857.image_5F00_thumb_5F00_781BF4CB.png" width="159" height="133" /></a></p>  <p>We are almost done, usually Mvc base assembies are in .net 4 GAC, we need to take these files to your <strong>Bin</strong> folder:</p>  <ul>   <li>Microsoft.Web.Infrastructure.dll </li>    <li>System.Web.Helpers.dll </li>    <li>System.Web.Mvc.dll </li>    <li>System.Web.Razor.dll </li>    <li><strike>System.Web.WebPages.Administration.dll</strike> </li>    <li>System.Web.WebPages.Deployment.dll </li>    <li>System.Web.WebPages.dll </li>    <li>System.Web.WebPages.Razor.dll </li> </ul>  <p>You can get them from C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies and C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies , from the box you installed MVC3, most likely it is your develop machine.</p>  <p>The reason why I stroke out the System.Web.WebPage.Administratration.dll is if you copy that file, you need to also copy the NuGet.Core.dll, but if none of them are available, the site can also work.</p>  <p>For other IIS settings like authentication, SSL and logging, etc, you can use appcmd.exe to do the automation, it is located in %windir%\System32\inetsrv</p>]]></content:encoded>
    </item>
    <item>
      <title>UDisk + WinPE 3.0 = New deployment solution</title>
      <link>https://docs.microsoft.com/archive/blogs/tiche/udisk-winpe-3-0-new-deployment-solution</link>
      <pubDate>Sun, 12 Jul 2009 11:12:00 GMT</pubDate>
      <dc:creator><![CDATA[tiche MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/tiche/2009/07/12/udisk-winpe-3-0-new-deployment-solution/</guid>
      <description><![CDATA[draft, just a test for WLW]]></description>
      <content:encoded><![CDATA[<P>draft, just a test for WLW</P>]]></content:encoded>
    </item>
  </channel>
</rss>