<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Codebureau - Matt Simner</title>
    <link>http://www.codebureau.com/blog/</link>
    <description>(Not) just another .NET Developer</description>
    <language>en-us</language>
    <copyright>Matt Simner</copyright>
    <lastBuildDate>Mon, 17 Oct 2011 02:47:37 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>matt.simner@cheniston.com</managingEditor>
    <webMaster>matt.simner@cheniston.com</webMaster>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodebureauMattSimner" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="codebureaumattsimner" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e</wfw:commentRss>
      
      <title>NDepend - Visual Studio Addin: takes you as far as you want to go</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e.aspx</guid>
      <link>http://www.codebureau.com/blog/2011/10/17/NDependVisualStudioAddinTakesYouAsFarAsYouWantToGo.aspx</link>
      <pubDate>Mon, 17 Oct 2011 02:47:37 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;font size="1"&gt;&#xD;
          &lt;i&gt;&#xD;
            &lt;font face="Verdana"&gt;First&#xD;
of all I'd like to point out that I was kindly given a license by the folks at NDepend&#xD;
(not very often that sort of thing happens I can assure you!) and I'm under absolutely&#xD;
no obligation to write anything about it.&lt;/font&gt;&#xD;
          &lt;/i&gt;&#xD;
        &lt;/font&gt;&#xD;
        &lt;br&gt;&#xD;
        &lt;h3&gt;In the beginning...&#xD;
&lt;/h3&gt;&#xD;
The funny thing is that it was probably over a year ago when I first installed the&#xD;
product without any specific requirement or expectation. I had a little play with&#xD;
it (on Visual Studio 2008 as I recall), then the work I 'had' to do overtook my will&#xD;
to learn this new product and it lay gathering dust on my hard drive.  &lt;i&gt;&lt;font size="1"&gt;This&#xD;
probably explains why I haven't posted in all that time!&lt;/font&gt;&lt;/i&gt;&lt;br&gt;&lt;h3&gt;But then...&#xD;
&lt;/h3&gt;&#xD;
Recently, I picked up an existing project (on visual Studio 2010), and wanted to have&#xD;
a good look inside to see what I was getting myself into. I dusted off NDepend and&#xD;
told myself I'd give it a good go this time...&lt;br&gt;&lt;br&gt;&lt;h3&gt;First Impressions&#xD;
&lt;/h3&gt;&#xD;
The first thing I learned is that this is one significant addin, and you realistically&#xD;
need to 'know you need it' before you get it (see 'laying dormant comment above').&#xD;
This also means you need to know what it can do for you - which is plenty!&lt;br&gt;&lt;br&gt;&#xD;
If you're reading this and thinking of trialling NDepend, then you either have problems&#xD;
to solve or you're wanting to invest in ongoing improvement to your code. Both are&#xD;
very good reasons as it happens.&lt;br&gt;&lt;br&gt;&#xD;
NDepend has few limitations in what it can do, as it has your entire codebase, Visual&#xD;
Studio extensibility and its own powerful rules engine at its disposal. It also employs&#xD;
its own CQL (code query language), to allow you to find all sorts of patterns and&#xD;
complexity problems with your code.&lt;br&gt;&lt;br&gt;&#xD;
The biggest problem is knowing where to start, or discovering that first task you&#xD;
want to achieve with it. It's easy to get overwhelmed by the information it bombards&#xD;
you with when you spin it up).&lt;br&gt;&lt;br&gt;&lt;img src="content/binary/ndepend.png" border="0"&gt;&lt;/img&gt;&lt;br&gt;&lt;br&gt;&#xD;
To be fair, there's plenty of links trying to lead you to 'what you're looking at&#xD;
is...'&lt;br&gt;&lt;h3&gt;Reasons to try/buy&#xD;
&lt;/h3&gt;&#xD;
If you're interested in the quality of your code I believe there really is no equal. &lt;b&gt;This&#xD;
is the tool you need.&lt;/b&gt; You may already be using FX Cop in your build process to&#xD;
check for certain snytactical rules, and ReSharper for sorting out your code as you&#xD;
go, but NDepend can do all sorts of 'different' funky stuff (through CQL) that goes&#xD;
in depth to your code to enforce things that would be otherwise difficult to do &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
It can obviously do all the simple stuff like show you where your dependencies are&#xD;
between methods, classes and projects, and redundant code etc.&lt;br&gt;&lt;br&gt;&#xD;
Some highlights I quite like - made possible through CQL: &#xD;
&lt;br&gt;&lt;ul&gt;&lt;li&gt;&#xD;
Enforcing of layering constraints - i.e. 'this UI project cannot directly reference&#xD;
'that' 'DAL' project&lt;/li&gt;&lt;li&gt;&#xD;
Simple spot check stuff like queries on a 'lines of code' threshold - indicating complexity&lt;/li&gt;&lt;li&gt;&#xD;
Code not meeting an acceptable test coverage&lt;/li&gt;&lt;li&gt;&#xD;
For all the possibilities you'll need to look &lt;a href="http://www.ndepend.com/Features.aspx#CQL"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Things to be aware of&#xD;
&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&#xD;
It's a technical tool, and it's easy to get a little overwhelmed with what it can&#xD;
do and where to start.&lt;/li&gt;&lt;li&gt;&#xD;
Time is needed to understand some of the concepts and power of the product.&lt;/li&gt;&lt;li&gt;&#xD;
You'll need a beefy machine to avoid things slowing down with the addin loaded (I&#xD;
had to disable it for a while when I was using a solution with 60 projects as I was&#xD;
starting to experience memory issues).  If you don't want to run it in Visual&#xD;
Studio, you can run it in the standalone 'Visual NDepend' application.&lt;br&gt;&lt;/li&gt;&lt;li&gt;&#xD;
I'll admit I haven't spent a lot of time with the interactive reports, and I don't&#xD;
find some of the graphical representations of the metrics that easy to use. &#xD;
&lt;br&gt;&lt;/li&gt;&lt;li&gt;&#xD;
I think like most products, you get comfortable with what you see as valuable, and&#xD;
tend to only try other things when you have time.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Summary&#xD;
&lt;/h3&gt;&#xD;
Clearly NDepend's a very impressive tool for any serious development team to be using.&#xD;
It will help you to learn about reducing complexity, dependencies and generally designing&#xD;
your code in an efficient way. It's basically all about improving quality.&lt;br&gt;&lt;br&gt;&#xD;
It's also a big product that's not for the faint hearted. You basically get out what&#xD;
you put in as far as effort in understanding what it's trying to achieve for you. &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
I think the key is finding the right balance between all the technical information&#xD;
it presents, the time you have available, and the business benefit you'll get from&#xD;
code improvements.&lt;br&gt;&lt;br&gt;&#xD;
As I said at the start. It can basically take you as far as 'you' want to go. &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
Worth taking a look at: &lt;a target="_blank" class="ext-link" href="http://www.ndepend.com/"&gt;http://www.ndepend.com/&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;br&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=0jVlRJVFUho:50ukwCyfYlk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=0jVlRJVFUho:50ukwCyfYlk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=0jVlRJVFUho:50ukwCyfYlk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=0jVlRJVFUho:50ukwCyfYlk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=0jVlRJVFUho:50ukwCyfYlk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/0jVlRJVFUho" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,fb2f4f5c-04ff-4c19-b1a2-b9486ccc592e.aspx</comments>
      <category>Refactoring</category>
      <category>Tools</category>
      <category>Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=e8ca7b29-af7d-489e-83d3-52b11bd19d09</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,e8ca7b29-af7d-489e-83d3-52b11bd19d09.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,e8ca7b29-af7d-489e-83d3-52b11bd19d09.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e8ca7b29-af7d-489e-83d3-52b11bd19d09</wfw:commentRss>
      
      <title>LINQ Group by MAX Date Query</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,e8ca7b29-af7d-489e-83d3-52b11bd19d09.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/07/07/LINQGroupByMAXDateQuery.aspx</link>
      <pubDate>Wed, 07 Jul 2010 05:02:18 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;I've found some weird, wonderful and ridiculously&#xD;
complicated LINQ queries for getting the row with MAX(DATE) based on a key. &#xD;
Most unnecessarily use lambda expressions, and some just had several interim steps. &#xD;
I knew there had to be a better way, and found an unassuming post at the bottom of&#xD;
a &lt;a href="http://stackoverflow.com/questions/976808/linq-group-by-with-a-sub-query"&gt;StackOverflow&#xD;
page&lt;/a&gt;.&lt;br&gt;&lt;br&gt;&#xD;
Here's my non-lambda'd, contrived example...  assuming you've got an EntityFramework&#xD;
model (i.e. context)&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Get&#xD;
Client Order with (max) order date &lt;/span&gt; var maxclientOrder &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (from&#xD;
clientOrder &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; context.ClientOrders&#xD;
where clientOrder.OrderDate == (from clientOrder2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; context.ClientOrders&#xD;
where clientOrder2.ClientID == clientOrder.ClientID select clientOrder2.OrderDate).Max()&#xD;
select clientOrder).ToList();&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=e8ca7b29-af7d-489e-83d3-52b11bd19d09"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=V-tf_ehhNiU:5iyVA1qnkHE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=V-tf_ehhNiU:5iyVA1qnkHE:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=V-tf_ehhNiU:5iyVA1qnkHE:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=V-tf_ehhNiU:5iyVA1qnkHE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=V-tf_ehhNiU:5iyVA1qnkHE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/V-tf_ehhNiU" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,e8ca7b29-af7d-489e-83d3-52b11bd19d09.aspx</comments>
      <category>C#</category>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=6831c7e3-65b5-45a7-955f-1bd7e8bf12a1</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,6831c7e3-65b5-45a7-955f-1bd7e8bf12a1.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,6831c7e3-65b5-45a7-955f-1bd7e8bf12a1.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6831c7e3-65b5-45a7-955f-1bd7e8bf12a1</wfw:commentRss>
      <slash:comments>2</slash:comments>
      
      <title>Simple WPF Page Navigation From an MVVM ViewModel</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,6831c7e3-65b5-45a7-955f-1bd7e8bf12a1.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/07/05/SimpleWPFPageNavigationFromAnMVVMViewModel.aspx</link>
      <pubDate>Mon, 05 Jul 2010 05:00:20 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;Navigation in WPF is easy - unless of course&#xD;
you're trying to apply an MVVM pattern.  Most examples tell you about all the&#xD;
great things you can do with MVVM/WPF whilst brushing such things as navigation under&#xD;
the carpet.  I've not found one person who's adequately explained an MVVM example&#xD;
with 'all' of the facets you'll need when writing a real application.&lt;br&gt;&lt;br&gt;&#xD;
I'm not going to tell you how to implement full-scale configurable multi-context navigation&#xD;
using MVVM, but I'll briefly discuss one approach to a nagging issue - that of triggering&#xD;
and controlling navigation from the ViewModel.  I'm also talking specifically&#xD;
about 'pages' here too, as I'm targeting a browser with this application.&lt;br&gt;&lt;br&gt;&#xD;
WPF 'Page' objects expose a &lt;font face="Courier New"&gt;NavigationService &lt;/font&gt;property,&#xD;
which hooks into the WPF navigation framework.  This is very convenient and powerful. &#xD;
MVVM effectively steers you away from doing anything behind your 'views', and tries&#xD;
to substitute the traditional coupling between view/controller/viewmodel (depending&#xD;
on the flavour) with reliance on data binding to give the viewmodel everything it&#xD;
needs to perform all the UI logic.&lt;br&gt;&lt;br&gt;&#xD;
Your ViewModel isn't supposed to have any reference to (or knowledge of) your view. &#xD;
This means you won't have a reference to the Page to be able to access its &lt;font face="Courier New"&gt;NavigationService&lt;/font&gt;. &#xD;
There's other ways to navigate, like using more of a frame appropach (most of the&#xD;
examples so this), but if you want to navigate 'web-style' from Page1 to Page2 to&#xD;
Page3 etc - controlling this from your ViewModel, what do you do?&lt;br&gt;&lt;br&gt;&#xD;
After messing around with quite a number of approaches I've currently settled for&#xD;
a very simple technique that doesn't feel 'too' dirty.  It became clear (in my&#xD;
case) that loading the ViewModel from the View is actually more appropriate and practical&#xD;
than loading the view from the ViewModel (through a DataTemplate mapping as others&#xD;
would suggest).  I found starting everything from the ViewModel paints you into&#xD;
something of a technical corner, as some core WPF functionality only exists at the&#xD;
view level.  You can of course write your own implementations, but I've always&#xD;
thought patterns are meant to 'help', and when they cease to help, you stop.&lt;br&gt;&lt;br&gt;&#xD;
In our example, the Application object effectively sets things up by being the all-seeing&#xD;
eye on the navigation framework.&lt;br&gt;&lt;br&gt;&#xD;
The code below simply sets the startup uri (from another library), and subscribes&#xD;
to the 'navigated' event, which will fire after every page movement.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; partial &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; App&#xD;
: Application { &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; NavigationService&#xD;
navigator; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;override&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; OnStartup(StartupEventArgs&#xD;
e) { &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;base&lt;/span&gt;.OnStartup(e); &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.StartupUri &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;br&gt;&#xD;
new&lt;/span&gt; Uri(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"pack://application:,,,/MyPageLibrary;component/MyStartupPage.xaml"&lt;/span&gt;);&#xD;
} &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; App_Navigated(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,&#xD;
NavigationEventArgs e) { Page page &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; e.Content &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;as&lt;/span&gt; Page; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (page&#xD;
!&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)&#xD;
ApplicationHelper.NavigationService &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; page.NavigationService;&#xD;
} }&lt;/span&gt;&lt;/pre&gt;The ApplicationHelper class is a simple static implementation to provide&#xD;
the whole application with what is in effect a 'bus' service - the means to navigate,&#xD;
using the NavigationService injected from the Application.  &lt;i&gt;I said this was&#xD;
simple&lt;/i&gt;.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; ApplicationHelper&#xD;
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; NavigationService&#xD;
navigator; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; NavigationService&#xD;
NavigationService { set { navigator &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; value;&#xD;
} get { &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; navigator;&#xD;
} } }&lt;/span&gt;&lt;/pre&gt;The ViewModel is then free to navigate whereever it likes (I'm constructing&#xD;
the pages as objects here with parameters to use in constructing the viewmodel, rather&#xD;
than using a uri).&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Now&#xD;
navigate to the detail view&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Datacontext&#xD;
used to construct the ViewModel&lt;/span&gt;&lt;br&gt;&lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt; MyNextPage&#xD;
nextPage &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; MyNextPage(SomeDataContext); &#xD;
&lt;br&gt;&#xD;
ApplicationHelper.NavigationService.Navigate(nextPage);&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&#xD;
I'm sure this will evolve again (like everything I'm finding with WPF), but for now&#xD;
this seems to perform my basic requirements&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=6831c7e3-65b5-45a7-955f-1bd7e8bf12a1"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=zFarmHqdua0:oxfVUUqbB3U:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=zFarmHqdua0:oxfVUUqbB3U:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=zFarmHqdua0:oxfVUUqbB3U:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=zFarmHqdua0:oxfVUUqbB3U:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=zFarmHqdua0:oxfVUUqbB3U:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/zFarmHqdua0" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,6831c7e3-65b5-45a7-955f-1bd7e8bf12a1.aspx</comments>
      <category>C#</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=f2c4890b-cc66-4ce7-8081-2d1e65d88412</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,f2c4890b-cc66-4ce7-8081-2d1e65d88412.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,f2c4890b-cc66-4ce7-8081-2d1e65d88412.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=f2c4890b-cc66-4ce7-8081-2d1e65d88412</wfw:commentRss>
      <slash:comments>2</slash:comments>
      
      <title>Generate SQL Server Inserts from existing data - with Identity Inserts</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,f2c4890b-cc66-4ce7-8081-2d1e65d88412.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/06/23/GenerateSQLServerInsertsFromExistingDataWithIdentityInserts.aspx</link>
      <pubDate>Wed, 23 Jun 2010 00:03:29 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;A good while ago I &lt;a href="http://www.codebureau.com/blog/2008/07/07/GenerateSQLInsertsFromExistingData.aspx"&gt;posted&#xD;
a stored proc&lt;/a&gt; that would generate insert statements for table data, along with&#xD;
simple filtering capability.&lt;br&gt;&lt;br&gt;&#xD;
I broke this out again today, as I needed to recreate part of a database on a local&#xD;
machine.  I didn't have knowledge of the schema so I just went about fixing each&#xD;
constraint error and adding the reference tables as required to my script.  After&#xD;
manually adding 'SET IDENTITY_INSERT xx' about a dozen times I added the functionality&#xD;
to the Stored Proc - so if your table has an identity column it will now wrap the&#xD;
results in IDENTITY_INSERT statements, saving you a bit more time, and headaches.&lt;br&gt;&lt;br&gt;&#xD;
An interesing side effect if you're explicitly inserting identity values is that the&#xD;
order of your inserts may become pertinent - especially if you've got foreign keys&#xD;
referencing the same table.  I then just added the capability to 'order by'.&lt;br&gt;&#xD;
 &lt;br&gt;&#xD;
There's no automatic way to switch off column headers, so you'll need to configure&#xD;
that in the Resutls Output options in Query Analyzer (or management studio).&lt;br&gt;&lt;br&gt;&#xD;
If you run the proc into 'Northwind' and run:&lt;br&gt;&lt;br&gt;&lt;font face="Courier New" size="2"&gt;usp_insertgenerator Employees, @order='EmployeeID'&lt;/font&gt;&lt;br&gt;&lt;br&gt;&#xD;
You'll get...&lt;br&gt;&lt;br&gt;&lt;font face="Courier New" size="1"&gt;SET IDENTITY_INSERT Employees ON&lt;br&gt;&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('1','Davolio','Nancy','Sales Representative','Ms.',convert(dateti&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('2','Fuller','Andrew','Vice President, Sales','Dr.',convert(datet&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('3','Leverling','Janet','Sales Representative','Ms.',convert(date&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('4','Peacock','Margaret','Sales Representative','Mrs.',convert(da&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('5','Buchanan','Steven','Sales Manager','Mr.',convert(datetime,'1&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('6','Suyama','Michael','Sales Representative','Mr.',convert(datet&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('7','King','Robert','Sales Representative','Mr.',convert(datetime&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('8','Callahan','Laura','Inside Sales Coordinator','Ms.',convert(d&lt;br&gt;&#xD;
INSERT Employees(EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,&lt;br&gt;&#xD;
Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) &#xD;
&lt;br&gt;&#xD;
  VALUES('9','Dodsworth','Anne','Sales Representative','Ms.',convert(datet&lt;br&gt;&lt;br&gt;&#xD;
SET IDENTITY_INSERT Employees OFF&lt;/font&gt;&lt;br&gt;&lt;br&gt;&#xD;
Here's the script.&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;div style="overflow: scroll;"&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt;&lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;exists&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;select&lt;/span&gt; * &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;from&lt;/span&gt; dbo.&lt;span style="color: LawnGreen; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;sysobjects&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;where&lt;/span&gt; id&#xD;
= &lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object_id&lt;/span&gt;(N&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'[dbo].[usp_InsertGenerator]'&lt;/span&gt;) &lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;and&lt;/span&gt;&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;OBJECTPROPERTY&lt;/span&gt;(id,&#xD;
N&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'IsProcedure'&lt;/span&gt;)&#xD;
= 1) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;drop&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;procedure&lt;/span&gt; [dbo].[usp_InsertGenerator]&#xD;
GO &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;CREATE&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;PROC&lt;/span&gt; dbo.usp_InsertGenerator&#xD;
(@tableName &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;varchar&lt;/span&gt;(100),&#xD;
@&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;where&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;varchar&lt;/span&gt;(1000)&#xD;
= &lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NULL&lt;/span&gt;,&#xD;
@&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;order&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;varchar&lt;/span&gt;(1000)&#xD;
= &lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NULL&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;as&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NOCOUNT&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ON&lt;/span&gt;&lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--Check&#xD;
whether the table has an identity column&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; @TableHasIdentityColumn &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BIT&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SELECT&lt;/span&gt; @TableHasIdentityColumn&#xD;
= 1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;from&lt;/span&gt; INFORMATION_SCHEMA.COLUMNS &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;where&lt;/span&gt; TABLE_SCHEMA&#xD;
= &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'dbo'&lt;/span&gt;&lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;and&lt;/span&gt;&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;COLUMNPROPERTY&lt;/span&gt;(&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object_id&lt;/span&gt;(TABLE_NAME),&#xD;
COLUMN_NAME, &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'IsIdentity'&lt;/span&gt;)&#xD;
= 1 &lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;AND&lt;/span&gt; TABLE_NAME&#xD;
= @tableName &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt;&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ISNULL&lt;/span&gt;(@TableHasIdentityColumn,&#xD;
0) = 1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;PRINT&lt;/span&gt;&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'SET&#xD;
IDENTITY_INSERT '&lt;/span&gt; + @tableName + &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
ON'&lt;/span&gt;&lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--Declare&#xD;
a cursor to retrieve column specific information for the specified table&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; cursCol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;CURSOR&lt;/span&gt; FAST_FORWARD &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;FOR&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SELECT&lt;/span&gt; column_name,data_type &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;FROM&lt;/span&gt; information_schema.columns &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;WHERE&lt;/span&gt; table_name&#xD;
= @tableName &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;OPEN&lt;/span&gt; cursCol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; @string &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;nvarchar&lt;/span&gt;(3000) &lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--for&#xD;
storing the first half of INSERT statement&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; @stringData &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;nvarchar&lt;/span&gt;(3000) &lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--for&#xD;
storing the data (VALUES) related statement&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; @dataType &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;nvarchar&lt;/span&gt;(1000) &lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--data&#xD;
types returned for respective columns&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @string=&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'INSERT&#xD;
'&lt;/span&gt;+@tableName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'('&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;''&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; @colName &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;nvarchar&lt;/span&gt;(50) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;FROM&lt;/span&gt; cursCol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;INTO&lt;/span&gt; @colName,@dataType &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt;&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;@@fetch_status&lt;/span&gt;&amp;lt;&amp;gt;0 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;begin&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;print&lt;/span&gt;&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'Table&#xD;
'&lt;/span&gt;+@tableName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
not found, processing skipped.'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;close&lt;/span&gt; curscol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;deallocate&lt;/span&gt; curscol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;WHILE&lt;/span&gt;&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;@@FETCH_STATUS&lt;/span&gt;=0 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt; @dataType &lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; (&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'varchar'&lt;/span&gt;,&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'char'&lt;/span&gt;,&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'nchar'&lt;/span&gt;,&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'nvarchar'&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=@stringData+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''+isnull('''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''''+'&lt;/span&gt;+&#xD;
@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'+'''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;''''',''NULL'')+'',''+'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ELSE&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; @dataType &lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; (&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'text'&lt;/span&gt;,&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'ntext'&lt;/span&gt;) &lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--if&#xD;
the datatype is text or something else &lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=@stringData+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''''''''+isnull(cast('&lt;/span&gt;+&#xD;
@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
as varchar(2000)),'''')+'''''',''+'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ELSE&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt; @dataType&#xD;
= &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'money'&lt;/span&gt;&lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--because&#xD;
money doesn't get converted from varchar implicitly&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=@stringData+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''convert(money,''''''+isnull(cast('&lt;/span&gt;+&#xD;
@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
as varchar(200)),''0.0000'')+''''''),''+'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ELSE&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt; @dataType=&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'datetime'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=@stringData+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''convert(datetime,'&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''+isnull('''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''''+convert(varchar(200),'&lt;/span&gt;+&#xD;
@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;',121)+'''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;''''',''NULL'')+'',121),''+'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ELSE&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt; @dataType=&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'image'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=@stringData+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''''''''+isnull(cast(convert(varbinary,'&lt;/span&gt;+&#xD;
@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;')&#xD;
as varchar(6)),''0'')+'''''',''+'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ELSE&lt;/span&gt;&lt;span style="color: Teal; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;--presuming&#xD;
the data type is int,bit,numeric,decimal &lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;BEGIN&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @stringData=@stringData+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''+isnull('''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''''+convert(varchar(200),'&lt;/span&gt;+&#xD;
@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;')+'''''&lt;/span&gt;+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;''''',''NULL'')+'',''+'&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @string=@string+@colName+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;','&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;FROM&lt;/span&gt; cursCol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;INTO&lt;/span&gt; @colName,@dataType &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;END&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DECLARE&lt;/span&gt; @Query &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;nvarchar&lt;/span&gt;(4000) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @query&#xD;
=&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'SELECT&#xD;
'''&lt;/span&gt;+&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;substring&lt;/span&gt;(@string,0,&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;len&lt;/span&gt;(@string))&#xD;
+ &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;')&#xD;
VALUES(''+ '&lt;/span&gt; + &lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;substring&lt;/span&gt;(@stringData,0,&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;len&lt;/span&gt;(@stringData)-2)+&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''+'')''&#xD;
FROM '&lt;/span&gt;+@tableName &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt; @&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;where&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IS&lt;/span&gt;&lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NOT&lt;/span&gt;&lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NULL&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @query&#xD;
= @query + &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
where '&lt;/span&gt; + @&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;where&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt; @&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;order&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IS&lt;/span&gt;&lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NOT&lt;/span&gt;&lt;span style="color: Silver; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;NULL&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;SET&lt;/span&gt; @query&#xD;
= @query + &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
order by '&lt;/span&gt; + @&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;order&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;exec&lt;/span&gt;&lt;span style="color: Brown; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;sp_executesql&lt;/span&gt; @query &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;CLOSE&lt;/span&gt; cursCol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;DEALLOCATE&lt;/span&gt; cursCol &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;IF&lt;/span&gt;&lt;span style="color: Fuchsia; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ISNULL&lt;/span&gt;(@TableHasIdentityColumn,&#xD;
0) = 1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;PRINT&lt;/span&gt;&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'SET&#xD;
IDENTITY_INSERT '&lt;/span&gt; + @tableName + &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'&#xD;
OFF'&lt;/span&gt; GO &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=f2c4890b-cc66-4ce7-8081-2d1e65d88412"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=4tqsDjFg8-I:G9bBM3Fjr8g:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=4tqsDjFg8-I:G9bBM3Fjr8g:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=4tqsDjFg8-I:G9bBM3Fjr8g:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=4tqsDjFg8-I:G9bBM3Fjr8g:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=4tqsDjFg8-I:G9bBM3Fjr8g:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/4tqsDjFg8-I" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,f2c4890b-cc66-4ce7-8081-2d1e65d88412.aspx</comments>
      <category>Setup and Deployment</category>
      <category>SQL Server</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=63ef1412-a22a-453e-a59e-62fcc05781be</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,63ef1412-a22a-453e-a59e-62fcc05781be.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,63ef1412-a22a-453e-a59e-62fcc05781be.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=63ef1412-a22a-453e-a59e-62fcc05781be</wfw:commentRss>
      
      <title>Use SQL Server Trusted Connections with ASP.NET on Windows 2003 without impersonation</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,63ef1412-a22a-453e-a59e-62fcc05781be.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/06/17/UseSQLServerTrustedConnectionsWithASPNETOnWindows2003WithoutImpersonation.aspx</link>
      <pubDate>Thu, 17 Jun 2010 01:15:53 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;Access control and troubleshooting 401&#xD;
errors must be one of the most annoying and recurring issues with configuring IIS. &#xD;
One of the problems is that it's often quite a long time between issues, and you simply&#xD;
forget how you solved something last time.  This time I decided to write it all&#xD;
down as I set things up.&lt;br&gt;&lt;br&gt;&lt;b&gt;Target Scenario&lt;/b&gt;&lt;br&gt;&#xD;
My target scenario is a local intranet, where you want to use a 'service account'&#xD;
to access SQL Server, directly from your 'trusted' web application, removing the need&#xD;
for impersonation.  &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
The benefits of this are of course that you can take advantage of connection pooling,&#xD;
but also removing the need to configure passwords in web.config for SQL users (or&#xD;
specific, impersonated domain users).  This also removed the overhead of configuring&#xD;
specific domain users and their SQL Server permissions.  It may also be that&#xD;
you just want to simplify your security model to work only on Windows authentication&#xD;
across the stack.  &lt;br&gt;&lt;br&gt;&lt;b&gt;SQL Server&lt;/b&gt;&lt;br&gt;&lt;ol&gt;&lt;li&gt;&#xD;
Create a new role in the database you're accessing, for the purposes of your application&lt;/li&gt;&lt;li&gt;&#xD;
Add your service domain user account to the role in SQL Server&lt;/li&gt;&lt;li&gt;&#xD;
Assign permissions to objects, stored procedures etc to the role (not directly to&#xD;
the user)&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;&lt;b&gt;IIS/Web Site&lt;/b&gt;&lt;br&gt;&lt;ol&gt;&lt;li&gt;&#xD;
Set up your web site/application as you would normally - one way to do things....&lt;/li&gt;&lt;/ol&gt;&lt;ol&gt;&lt;li&gt;&#xD;
Create your web application root folder on the web server&lt;/li&gt;&lt;li&gt;&#xD;
Copy your files (or use your deployment tools/scripts to do this)&lt;/li&gt;&lt;li&gt;&#xD;
Create a new application pool to house your new web application (probably model this&#xD;
from the default web site).  This is important as this is where the credentials&#xD;
will be set&lt;/li&gt;&lt;li&gt;&#xD;
Create the new IIS web application against the root folder (if not already done as&#xD;
part of step 2)&lt;/li&gt;&lt;li&gt;&#xD;
Associate the new IIS application with the new application pool&lt;/li&gt;&lt;li&gt;&#xD;
Set the ASP.NET version of your IIS application appropriate (may need to restart IIS&#xD;
here)&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&#xD;
Ensure 'Integrated Security' is set ON in the Directory Security tab, and 'Anonymous'&#xD;
access is switched OFF&lt;/li&gt;&lt;li&gt;&#xD;
Set the application pool's 'identity' to the domain user you want to run the application&#xD;
(and connect to SQL Server) as&lt;/li&gt;&lt;li&gt;&#xD;
Open a command window and Go to the windows\Microsoft.NET\Framework\vXXXXX folder&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&#xD;
run aspnet_regiis -ga &amp;lt;domain&amp;gt;\&amp;lt;user&amp;gt; to grant necessary access to the&#xD;
metabase etc for the service account (as per &lt;a href="http://msdn.microsoft.com/en-us/library/ff647396.aspx#paght000008_step3"&gt;http://msdn.microsoft.com/en-us/library/ff647396.aspx#paght000008_step3&lt;/a&gt; )&lt;/li&gt;&lt;li&gt;&#xD;
In the command window go to the inetpub\adminscripts folder, and set NTAuthenticationHeaders&#xD;
metabase property as per instructions at &lt;a href="http://support.microsoft.com/kb/326985"&gt;http://support.microsoft.com/kb/326985&lt;/a&gt;. &#xD;
you can also use MetaEdit from the IIS Resource Kit to change this.  If you're&#xD;
fully configured to use Kerberos then you can potentially skip this step, as it's&#xD;
all about making IIS use NTLM authentication.&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&#xD;
Navigate to 'Web Service Extensions' in IIS Manager, and ensure that the ASP.NET version&#xD;
you're targeting is 'allowed'.  e.g. ASP.NET 4.0 is 'prohibited' by default.&lt;br&gt;&lt;/li&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;br&gt;&#xD;
So here we've circumvented the need to use impersonation by running the ASP.NET application&#xD;
as a specific domain user that is configured as a SQL Server Login, and granted the&#xD;
right access by means of a SQL Server role.  The main work is the plumbing to&#xD;
get IIS to work happily with that user in standard NTLM authentication (you may be&#xD;
able to use Kerberos depending on your network configuration).&lt;br&gt;&lt;br&gt;&#xD;
Other background on creating service accounts can be found at &lt;a href="http://msdn.microsoft.com/en-us/library/ms998297.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms998297.aspx&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=63ef1412-a22a-453e-a59e-62fcc05781be"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=rkziSfzbdpk:dK5X2VLa6pI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=rkziSfzbdpk:dK5X2VLa6pI:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=rkziSfzbdpk:dK5X2VLa6pI:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=rkziSfzbdpk:dK5X2VLa6pI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=rkziSfzbdpk:dK5X2VLa6pI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/rkziSfzbdpk" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,63ef1412-a22a-453e-a59e-62fcc05781be.aspx</comments>
      <category>ASP.NET</category>
      <category>Setup and Deployment</category>
      <category>SQL Server</category>
      <category>Web</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=e49a0235-639e-4c5c-98fa-5de1a34aefd3</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,e49a0235-639e-4c5c-98fa-5de1a34aefd3.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,e49a0235-639e-4c5c-98fa-5de1a34aefd3.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e49a0235-639e-4c5c-98fa-5de1a34aefd3</wfw:commentRss>
      <title>Run SharePoint Designer 2007 Workflows as System User</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,e49a0235-639e-4c5c-98fa-5de1a34aefd3.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/05/20/RunSharePointDesigner2007WorkflowsAsSystemUser.aspx</link>
      <pubDate>Thu, 20 May 2010 23:40:54 GMT</pubDate>
      <description>&lt;link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Cmsimner%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"&gt;
&lt;link rel="themeData" href="file:///C:%5CDOCUME%7E1%5Cmsimner%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"&gt;
&lt;link rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5Cmsimner%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml"&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:WordDocument&gt;
  &lt;w:View&gt;Normal&lt;/w:View&gt;
  &lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
  &lt;w:TrackMoves/&gt;
  &lt;w:TrackFormatting/&gt;
  &lt;w:PunctuationKerning/&gt;
  &lt;w:ValidateAgainstSchemas/&gt;
  &lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
  &lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
  &lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
  &lt;w:DoNotPromoteQF/&gt;
  &lt;w:LidThemeOther&gt;EN-AU&lt;/w:LidThemeOther&gt;
  &lt;w:LidThemeAsian&gt;X-NONE&lt;/w:LidThemeAsian&gt;
  &lt;w:LidThemeComplexScript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;
  &lt;w:Compatibility&gt;
   &lt;w:BreakWrappedTables/&gt;
   &lt;w:SnapToGridInCell/&gt;
   &lt;w:WrapTextWithPunct/&gt;
   &lt;w:UseAsianBreakRules/&gt;
   &lt;w:DontGrowAutofit/&gt;
   &lt;w:SplitPgBreakAndParaMark/&gt;
   &lt;w:DontVertAlignCellWithSp/&gt;
   &lt;w:DontBreakConstrainedForcedTables/&gt;
   &lt;w:DontVertAlignInTxbx/&gt;
   &lt;w:Word11KerningPairs/&gt;
   &lt;w:CachedColBalance/&gt;
  &lt;/w:Compatibility&gt;
  &lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
  &lt;m:mathPr&gt;
   &lt;m:mathFont m:val="Cambria Math"/&gt;
   &lt;m:brkBin m:val="before"/&gt;
   &lt;m:brkBinSub m:val="&amp;#45;-"/&gt;
   &lt;m:smallFrac m:val="off"/&gt;
   &lt;m:dispDef/&gt;
   &lt;m:lMargin m:val="0"/&gt;
   &lt;m:rMargin m:val="0"/&gt;
   &lt;m:defJc m:val="centerGroup"/&gt;
   &lt;m:wrapIndent m:val="1440"/&gt;
   &lt;m:intLim m:val="subSup"/&gt;
   &lt;m:naryLim m:val="undOvr"/&gt;
  &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif]--&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
 &lt;w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
  DefSemiHidden="true" DefQFormat="false" DefPriority="99"
  LatentStyleCount="267"&gt;
  &lt;w:LsdException Locked="false" Priority="0" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Normal"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/&gt;
  &lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 7"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 8"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" Name="toc 9"/&gt;
  &lt;w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/&gt;
  &lt;w:LsdException Locked="false" Priority="10" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Title"/&gt;
  &lt;w:LsdException Locked="false" Priority="0" Name="Default Paragraph Font"/&gt;
  &lt;w:LsdException Locked="false" Priority="11" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/&gt;
  &lt;w:LsdException Locked="false" Priority="22" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Strong"/&gt;
  &lt;w:LsdException Locked="false" Priority="20" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/&gt;
  &lt;w:LsdException Locked="false" Priority="59" SemiHidden="false"
   UnhideWhenUsed="false" Name="Table Grid"/&gt;
  &lt;w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/&gt;
  &lt;w:LsdException Locked="false" Priority="1" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/&gt;
  &lt;w:LsdException Locked="false" Priority="34" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/&gt;
  &lt;w:LsdException Locked="false" Priority="29" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Quote"/&gt;
  &lt;w:LsdException Locked="false" Priority="30" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/&gt;
  &lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Shading Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light List Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
   UnhideWhenUsed="false" Name="Light Grid Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
   UnhideWhenUsed="false" Name="Dark List Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful List Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
   UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/&gt;
  &lt;w:LsdException Locked="false" Priority="19" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/&gt;
  &lt;w:LsdException Locked="false" Priority="21" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/&gt;
  &lt;w:LsdException Locked="false" Priority="31" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/&gt;
  &lt;w:LsdException Locked="false" Priority="32" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/&gt;
  &lt;w:LsdException Locked="false" Priority="33" SemiHidden="false"
   UnhideWhenUsed="false" QFormat="true" Name="Book Title"/&gt;
  &lt;w:LsdException Locked="false" Priority="37" Name="Bibliography"/&gt;
  &lt;w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/&gt;
 &lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt;
&lt;!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;
	mso-font-charset:0;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:-1610611985 1107304683 0 0 159 0;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:1627400839 -2147483648 8 0 66047 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-unhide:no;
	mso-style-qformat:yes;
	mso-style-parent:"";
	margin-top:0cm;
	margin-right:0cm;
	margin-bottom:10.0pt;
	margin-left:0cm;
	line-height:115%;
	mso-pagination:widow-orphan;
	font-size:11.0pt;
	font-family:"Tahoma","sans-serif";
	mso-fareast-font-family:"Times New Roman";
	mso-bidi-font-family:"Times New Roman";
	mso-fareast-language:EN-US;}
.MsoChpDefault
	{mso-style-type:export-only;
	mso-default-props:yes;
	font-size:10.0pt;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;
	mso-header-margin:36.0pt;
	mso-footer-margin:36.0pt;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
--&gt;
&lt;/style&gt;
&lt;!--[if gte mso 10]&gt;
&lt;style&gt;
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-priority:99;
	mso-style-qformat:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Calibri","sans-serif";}
&lt;/style&gt;
&lt;![endif]--&gt;
&lt;p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"&gt;
&lt;font size="2" face="Verdana"&gt;&lt;span style="font-size: 12pt; font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;;"&gt;&lt;font size="2" face="Verdana"&gt;There's
quite a bit of documentation and confusion around SharePoint Designer workflows and
the context under which they run.&amp;nbsp; I'd naively assumed that Workflows would run
in the context of the user that initiated the workflow, but with system user permissions.&lt;br&gt;
&lt;br&gt;
The following offers some insight and an approach for certain people to follow in
the case they have email-enabled libraries:&lt;br&gt;
&lt;a href="http://blogs.technet.com/victorbutuza/archive/2009/03/14/workflows-do-not-start.aspx"&gt;&lt;span style="color: blue;"&gt;http://blogs.technet.com/victorbutuza/archive/2009/03/14/workflows-do-not-start.aspx&lt;/span&gt;&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
This didn't help me, as I'd got some 'working' workflows that, once tested with a
non-privileged user simply didn't complete, as they hit permissions issues.&lt;br&gt;
&lt;br&gt;
The specific issue was that these users have the ability to add into a list, but not
edit, delete or approve, as the entry into the list is via a complex InfoPath form.&amp;nbsp;
Workflow actions occur on addition to the list to route the request to an appropriate
approver, and kick of an escalation process.&lt;br&gt;
&lt;br&gt;
It appears that SharePoint 2010 has a new &lt;a href="http://technet.microsoft.com/en-us/library/ee428324.aspx#BKMK_UserStep"&gt;&lt;span style="color: blue;"&gt;Impersonate
feature&lt;/span&gt;&lt;/a&gt; in Workflow, but hey - I'm still using 2007, and am 'specifically'
using SharePoint Designer (for business compatibility purposes).&amp;nbsp; I've used a
lot of third-party SPD Workflow actions from &lt;a href="http://www.nickgrattan.net/ActionPack.aspx"&gt;&lt;span style="color: blue;"&gt;Nick
Grattan&lt;/span&gt;&lt;/a&gt;, &lt;a href="http://ilovesharepoint.codeplex.com/releases/view/20898"&gt;&lt;span style="color: blue;"&gt;I
Love SharePoint&lt;/span&gt;&lt;/a&gt;, and wasn't about to be beaten, as I can currently do &lt;i&gt;everything&lt;/i&gt; I
need from SPD Workflows.&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
I finally found a solution that did exactly what I needed).&lt;br&gt;
&lt;br&gt;
Though vigorous googling, I found in the comments of the &lt;a href="http://spdactivities.codeplex.com/"&gt;&lt;b&gt;&lt;span style="color: blue;"&gt;Useful
SharePoint Workflow Activities&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;, that people were complaining that the
'&lt;b&gt;Start a Workflow&lt;/b&gt;' action was running the new workflow as the system user.&amp;nbsp;
Not me!&amp;nbsp; - that's exactly what I need.&lt;br&gt;
&lt;br&gt;
I downloaded and installed the activities, but had to apply &lt;a href="http://spdactivities.codeplex.com/WorkItem/View.aspx?WorkItemId=9216"&gt;&lt;span style="color: blue;"&gt;another
update&lt;/span&gt;&lt;/a&gt; to get them to work properly in SharePoint Designer.&lt;br&gt;
&lt;br&gt;
I now have a new 'wrapper' workflow, which is automatically called on 'new item' to
the list, and this calls the 2 existing workflows (now manually started), that were
previously set to be automatic.&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
This has had an added benefit, in that the ordering of these workflows is now consistent
as one is called after the other.&amp;nbsp; The only thing to bear in mind of course is
whether this behaviour is what you want, based on your situation.&lt;/font&gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=e49a0235-639e-4c5c-98fa-5de1a34aefd3" /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=eFo_TnFhf_Q:9aXBAgVX3AQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=eFo_TnFhf_Q:9aXBAgVX3AQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=eFo_TnFhf_Q:9aXBAgVX3AQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=eFo_TnFhf_Q:9aXBAgVX3AQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=eFo_TnFhf_Q:9aXBAgVX3AQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/eFo_TnFhf_Q" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,e49a0235-639e-4c5c-98fa-5de1a34aefd3.aspx</comments>
      <category>SharePoint</category>
      <category>Workflow</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=887e742b-7040-4e61-b5d5-8d693a7f1cbe</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,887e742b-7040-4e61-b5d5-8d693a7f1cbe.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,887e742b-7040-4e61-b5d5-8d693a7f1cbe.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=887e742b-7040-4e61-b5d5-8d693a7f1cbe</wfw:commentRss>
      
      <title>Fixing SharePoint error: No item exists at [url]?ID=n.  It may have been deleted or renamed by another user</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,887e742b-7040-4e61-b5d5-8d693a7f1cbe.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/05/05/FixingSharePointErrorNoItemExistsAtUrlIDnItMayHaveBeenDeletedOrRenamedByAnotherUser.aspx</link>
      <pubDate>Wed, 05 May 2010 23:10:51 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;Yesterday I was creating a page in SharePoint&#xD;
Designer and on testing got a server error:&lt;br&gt;&lt;br&gt;&#xD;
No item exists at http://sharepointsite/WebPages/My-Page?ID=56.  It may have&#xD;
been deleted or renamed by another user.&lt;br&gt;&lt;br&gt;&#xD;
I'd got code in the page that examined the 'ID' QueryString parameter and tried to&#xD;
load that item from a particular list.  This same code was working on another&#xD;
page.&lt;br&gt;&lt;br&gt;&lt;a href="http://support.microsoft.com/kb/972225"&gt;This MSDN article&lt;/a&gt; described the&#xD;
problem,&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;i&gt;This problem happens because Sharepoint has its own variable named ID which&#xD;
it uses to identify documents/pages on the server. Our solution should not be using&#xD;
a variable named ID. &lt;/i&gt;&lt;/pre&gt;I changed my QueryString parameter to RequestID instead&#xD;
and all was good, apart from the thought of why the other page still worked fine.  &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
I then realised that if it didn't know what list it was trying to target, then the&#xD;
'List' querystring parameter needs to be there too - as per other 'application page'&#xD;
requests in the _layouts folder, like approve/reject. &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
It then became obvious that I was doing too much work anyway:&lt;br&gt;&lt;br&gt;&#xD;
Passing in the List as well as the ID allows you to then just get straight to the&#xD;
list item with the following code...&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt; SPListItem&#xD;
item &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (SPListItem)SPContext.Current.Item; &lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&#xD;
as the List and ID are already taken care of.  A little neater than what I 'was'&#xD;
doing....&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt; SPListItem&#xD;
currentItem &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;;&#xD;
        &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Get&#xD;
ID and List Item information&lt;/span&gt;         requestList &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; SPContext.Current.Web.Lists[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"My&#xD;
List"&lt;/span&gt;];                 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (requestList&#xD;
!&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;&#xD;
Request.QueryString[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ID"&lt;/span&gt;]&#xD;
!&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)&#xD;
        {             &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;.TryParse(Request.QueryString[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ID"&lt;/span&gt;].ToString(), &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; requestID))&#xD;
            {                 &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Get&#xD;
Item&lt;/span&gt;                 currentItem &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; requestList.GetItemById(requestID);&#xD;
            }             &#xD;
        } &lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&#xD;
This code's still fine (apart from the querystring 'ID' name) if you need to load&#xD;
an item from a list that you don't know the guid for at the time.&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=887e742b-7040-4e61-b5d5-8d693a7f1cbe"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=qggdRFU0Kx8:1_u8oUqiIeQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=qggdRFU0Kx8:1_u8oUqiIeQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=qggdRFU0Kx8:1_u8oUqiIeQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=qggdRFU0Kx8:1_u8oUqiIeQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=qggdRFU0Kx8:1_u8oUqiIeQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/qggdRFU0Kx8" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,887e742b-7040-4e61-b5d5-8d693a7f1cbe.aspx</comments>
      <category>ASP.NET</category>
      <category>SharePoint</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=f900a17a-aa19-49db-80bb-03243619e497</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,f900a17a-aa19-49db-80bb-03243619e497.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,f900a17a-aa19-49db-80bb-03243619e497.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=f900a17a-aa19-49db-80bb-03243619e497</wfw:commentRss>
      
      <title>Pass in any parameter to an InfoPath form with one piece of code</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,f900a17a-aa19-49db-80bb-03243619e497.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/04/30/PassInAnyParameterToAnInfoPathFormWithOnePieceOfCode.aspx</link>
      <pubDate>Fri, 30 Apr 2010 00:18:22 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;One thing that's lacking in Microsoft InfoPath&#xD;
2007 is the ability to simply map input parameters to the main data source (which&#xD;
is most likely where you want them to go).  &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
Unfortunately there's no getting around the need to write code to 'receive' your input&#xD;
parameters, but with a thought you'll be able to pass in parameters with the same&#xD;
name as the fields in your form and have one block of code to paste into the code&#xD;
behind all forms - that will work for all.  &#xD;
&lt;br&gt;&lt;br&gt;&#xD;
This includes a couple of utility functions that make life a bit easier when coding&#xD;
around fields in the form.&lt;br&gt;&#xD;
The 'DeleteSelf' line around the nil attribute is something that apparently gets around&#xD;
data type errors if you've got fields that aren't just 'string' - e.g. 'number' etc. &#xD;
I found this worked in the InfoPath client, but not in a browser (and had to change&#xD;
my field data type back to string, and add some regexp validation).&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; FormEvents_Loading(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,&#xD;
LoadingEventArgs e) { &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Try&#xD;
and identify any input parameters and put them into their requisite places in the&#xD;
main data source&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;foreach&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; parameter &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; e.InputParameters.Keys)&#xD;
{ &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Try&#xD;
and find in the main data source, then set the value&lt;/span&gt; XPathNavigator formNode &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; SelectSingleNode(String.Format(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"//my:{0}"&lt;/span&gt;,&#xD;
parameter)); &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (formNode&#xD;
!&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)&#xD;
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (formNode.MoveToAttribute(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"nil"&lt;/span&gt;, &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;))&#xD;
formNode.DeleteSelf(); formNode &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; SelectSingleNode(String.Format(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"//my:{0}"&lt;/span&gt;,&#xD;
parameter)); formNode.SetValue(e.InputParameters[parameter]); } } } &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;///&#xD;
&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;///&#xD;
Select a single node from the Main data Source&lt;/span&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;///&#xD;
&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;///&#xD;
&amp;lt;param name="xpath"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;///&#xD;
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; XPathNavigator&#xD;
SelectSingleNode(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; xpath)&#xD;
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; ns &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; LookupNamespace(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"my"&lt;/span&gt;);&#xD;
XPathNavigator navigator &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; MainDataSource.CreateNavigator(); &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; navigator.SelectSingleNode(xpath,&#xD;
NamespaceManager); } &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; LookupNamespace(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; ns)&#xD;
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; NamespaceManager.LookupNamespace(ns);&#xD;
}&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=f900a17a-aa19-49db-80bb-03243619e497"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=RfR0wBSgS5A:WbqdRkJlmPc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=RfR0wBSgS5A:WbqdRkJlmPc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=RfR0wBSgS5A:WbqdRkJlmPc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=RfR0wBSgS5A:WbqdRkJlmPc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=RfR0wBSgS5A:WbqdRkJlmPc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/RfR0wBSgS5A" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,f900a17a-aa19-49db-80bb-03243619e497.aspx</comments>
      <category>InfoPath</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=a9b6512a-86c5-49ae-a694-13c9905ae02a</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,a9b6512a-86c5-49ae-a694-13c9905ae02a.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,a9b6512a-86c5-49ae-a694-13c9905ae02a.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=a9b6512a-86c5-49ae-a694-13c9905ae02a</wfw:commentRss>
      
      <title>Embedding InfoPath forms in SharePoint WebPart pages using the XmlFormView control</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,a9b6512a-86c5-49ae-a694-13c9905ae02a.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/04/29/EmbeddingInfoPathFormsInSharePointWebPartPagesUsingTheXmlFormViewControl.aspx</link>
      <pubDate>Thu, 29 Apr 2010 23:57:12 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;I recently needed to take a simple InfoPath&#xD;
form and surface that through a 'themed' SharePoint page.  It's possible to load&#xD;
the form in a browser without needing a specific page, but this effectively eliminates&#xD;
your master page from the equation.&lt;br&gt;&lt;br&gt;&#xD;
Nick Grattan wrote an &lt;a temp_href="http://www.nickgrattan.net/Publications/How to Host Microsoft InfoPath Forms in SharePoint Pages.pdf" href="http://www.nickgrattan.net/Publications/How%20to%20Host%20Microsoft%20InfoPath%20Forms%20in%20SharePoint%20Pages.pdf"&gt;excellent&#xD;
paper&lt;/a&gt; on using the XmlFormView control to contain InfoPath forms on SharePoint&#xD;
webpart pages.&lt;br&gt;&lt;br&gt;&#xD;
This is all great until you then need to send in input parameters to the form. &#xD;
I looked around for quite a while before I found the (rather obvious) Initialize event&#xD;
allows you to set the Input parameters of the form.  All other methods of loading&#xD;
the form (InfoPath client, FormServer.aspx) use a querystring-style format.&lt;br&gt;&lt;br&gt;&#xD;
The following code should do the trick in the case where you're passing information&#xD;
from a current 'list item' to the form:&lt;br&gt;&#xD;
 &lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; SPList&#xD;
requestList &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;;&#xD;
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; requestID;&#xD;
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; SPListItem&#xD;
currentItem &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;;&#xD;
    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,&#xD;
EventArgs e)     {         XmlformView1.Initialize    +=&#xD;
XmlformView1_Initialize;         &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Get&#xD;
ID and List Item information (passed into this page)&lt;/span&gt;         requestList &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; SPContext.Current.Web.Lists[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"My&#xD;
List"&lt;/span&gt;];                 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (requestList&#xD;
!&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;&#xD;
Request.QueryString[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ID"&lt;/span&gt;]&#xD;
!&lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)&#xD;
        {             &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;.TryParse(Request.QueryString[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ID"&lt;/span&gt;].ToString(), &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;out&lt;/span&gt; requestID))&#xD;
            {                 &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Get&#xD;
Item&lt;/span&gt;                 currentItem &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; requestList.GetItemById(requestID);&#xD;
                &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (currentItem&#xD;
== &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)&#xD;
                    &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;throw&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; ArgumentException(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"The&#xD;
specified ID does not exist"&lt;/span&gt;);             }&#xD;
                     }&#xD;
             }     &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; XmlformView1_Initialize(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,&#xD;
InitializeEventArgs e)     {         &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;//Set&#xD;
input parameters for embedded Form&lt;/span&gt;      e.InputParameters[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"foo"&lt;/span&gt;] &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; currentItem[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"foo"&lt;/span&gt;].ToString();&#xD;
     e.InputParameters[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"bar"&lt;/span&gt;] &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; currentItem[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"bar"&lt;/span&gt;].ToString();&#xD;
    } &lt;/span&gt;&lt;/pre&gt;I discovered that in order to write code in&#xD;
a WebPart page (using SharePoint Designer) you'll need to add a PageParserPath to&#xD;
the web.config as follows - otherwise you'll get an error saying something like 'code&#xD;
not allowed in this page'.  I've got a folder called 'WebPages' that houses the&#xD;
page.  The standard web.config already has the PageParserPaths element:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt; &amp;lt;SafeMode&#xD;
MaxControls=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"200"&lt;/span&gt; CallStack=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; DirectFileDependencies=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"10"&lt;/span&gt;&lt;br&gt;&#xD;
TotalFileDependencies=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"50"&lt;/span&gt; AllowPageLevelTrace=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"false"&lt;/span&gt;&amp;gt;&lt;br&gt;&#xD;
&amp;lt;PageParserPaths&amp;gt;&lt;br&gt;&#xD;
    &amp;lt;PageParserPath VirtualPath=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"/WebPages/*"&lt;/span&gt; CompilationMode=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Always"&lt;/span&gt;&lt;br&gt;&#xD;
AllowServerSideScript=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; IncludeSubFolders=&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"true"&lt;/span&gt; /&amp;gt;&lt;br&gt;&#xD;
&amp;lt;/PageParserPaths&amp;gt;&lt;br&gt;&#xD;
&amp;lt;/SafeMode&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;b&gt;&lt;br&gt;&#xD;
NOTE:&lt;/b&gt; If you're showing/hiding the form based on a flag/checkbox etc in the page&#xD;
(I'm doing this), then make sure you wrap the XmlFormView in a container Panel/div&#xD;
that you show/hide server-side, rather than showing/hiding the XmlFormView itself. &#xD;
For some reason this doesn't seem to work properly (at least in FireFox).&lt;br&gt;&lt;br&gt;&lt;p&gt;&lt;/p&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=a9b6512a-86c5-49ae-a694-13c9905ae02a"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=9n3jHHl5p4U:_c8DXmwfw7E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=9n3jHHl5p4U:_c8DXmwfw7E:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=9n3jHHl5p4U:_c8DXmwfw7E:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=9n3jHHl5p4U:_c8DXmwfw7E:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=9n3jHHl5p4U:_c8DXmwfw7E:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/9n3jHHl5p4U" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,a9b6512a-86c5-49ae-a694-13c9905ae02a.aspx</comments>
      <category>InfoPath</category>
      <category>SharePoint</category>
    </item>
    <item>
      <trackback:ping>http://www.codebureau.com/blog/Trackback.aspx?guid=28886e75-5b41-4c4b-abdf-7fa4270fc756</trackback:ping>
      <pingback:server>http://www.codebureau.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.codebureau.com/blog/PermaLink,guid,28886e75-5b41-4c4b-abdf-7fa4270fc756.aspx</pingback:target>
      <dc:creator>Matt Simner</dc:creator>
      <wfw:comment>http://www.codebureau.com/blog/CommentView,guid,28886e75-5b41-4c4b-abdf-7fa4270fc756.aspx</wfw:comment>
      <wfw:commentRss>http://www.codebureau.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=28886e75-5b41-4c4b-abdf-7fa4270fc756</wfw:commentRss>
      
      <title>LINQ to SQL Connection Strings with Class Library and Web.Config</title>
      <guid isPermaLink="false">http://www.codebureau.com/blog/PermaLink,guid,28886e75-5b41-4c4b-abdf-7fa4270fc756.aspx</guid>
      <link>http://www.codebureau.com/blog/2010/04/08/LINQToSQLConnectionStringsWithClassLibraryAndWebConfig.aspx</link>
      <pubDate>Thu, 08 Apr 2010 22:27:54 GMT</pubDate>
      <description>&lt;body xmlns="http://www.w3.org/1999/xhtml"&gt;Most Microsoft technologies that you can&#xD;
operate with a GUI come with some tradeoffs.  Things have certainly improved&#xD;
over the years and now something like the LINQ to SQL designer is pretty trouble free&#xD;
- unless of course you have something like this fairly common scenario:&lt;br&gt;&lt;br&gt;&#xD;
I had a class library (Data Access), and decided to add LINQ to SQL classes for a&#xD;
new database that was being introduced.&lt;br&gt;&#xD;
This class library is also ultimately being consumed by WCF web services.  I&#xD;
have dev, test, prod environments, so I use ASP.NET Web Deployment projects to change&#xD;
configuration per environment for things like appSettings and connectionStrings.&lt;br&gt;&lt;br&gt;&#xD;
It therefore followed that I wanted to configure the LINQ DataContext connection properties&#xD;
in web.config.  Out of the box you'll find your connection properties go into&#xD;
your Settings properties class, which gets a little bit in the way.&lt;br&gt;&lt;br&gt;&#xD;
If you start playing around with the generated classes to change where you're getting&#xD;
the connection info from then any changes in the designer will wipe them out, so a&#xD;
(relatively) pain free approach to setting your connection safely is the following:&lt;br&gt;&lt;br&gt;&lt;br&gt;&#xD;
Go to your LINQ to SQL designer and remove the Connection String, and set Application&#xD;
Settings to &lt;b&gt;False&lt;/b&gt;&lt;br&gt;&lt;img src="http://www.codebureau.com/blog/content/binary/linqconnection[1].png" border="0"&gt;&lt;/img&gt;&lt;br&gt;&#xD;
Create a new partial class to mirror your DataContext, and set the constructor to&#xD;
retrieve from your alternative source...&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System.Linq; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System.Configuration; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; System.Data.Linq; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;namespace&lt;/span&gt; CodeBureau.Services.DataAccess&#xD;
{ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; partial &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;class&lt;/span&gt; MyDataContext&#xD;
: DataContext { &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; MyDataContext()&#xD;
: &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;base&lt;/span&gt;(ConfigurationManager.ConnectionStrings[&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"MyConnectionString"&lt;/span&gt;].ConnectionString, &#xD;
&lt;br&gt;&#xD;
mappingSource) { OnCreated(); } } } &lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&#xD;
This will leave all your generated code intact, but will sort out your configuration&#xD;
woes.&lt;br&gt;&lt;img width="0" height="0" src="http://www.codebureau.com/blog/aggbug.ashx?id=28886e75-5b41-4c4b-abdf-7fa4270fc756"&gt;&lt;/img&gt;&lt;/body&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=ieCZWMQtvqs:GN9dGAP51jc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=ieCZWMQtvqs:GN9dGAP51jc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=ieCZWMQtvqs:GN9dGAP51jc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/CodebureauMattSimner?a=ieCZWMQtvqs:GN9dGAP51jc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/CodebureauMattSimner?i=ieCZWMQtvqs:GN9dGAP51jc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CodebureauMattSimner/~4/ieCZWMQtvqs" height="1" width="1"/&gt;</description>
      <comments>http://www.codebureau.com/blog/CommentView,guid,28886e75-5b41-4c4b-abdf-7fa4270fc756.aspx</comments>
      <category>.NET Framework</category>
      <category>C#</category>
      <category>LINQ</category>
    </item>
  </channel>
</rss>

