<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shane and Casey &#187; .NET</title>
	<atom:link href="http://www.shaneandcasey.com/category/technology/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaneandcasey.com</link>
	<description>Family, House, Home</description>
	<lastBuildDate>Fri, 18 Nov 2011 17:42:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>LINQ to SQL Dynamic Connection String</title>
		<link>http://www.shaneandcasey.com/2009/05/27/linq-to-sql-dynamic-connection-string/</link>
		<comments>http://www.shaneandcasey.com/2009/05/27/linq-to-sql-dynamic-connection-string/#comments</comments>
		<pubDate>Wed, 27 May 2009 19:17:11 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.shaneandcasey.com/?p=497</guid>
		<description><![CDATA[Note: If you are subscribed to our blog for house related content, and would prefer not to read nerd-speak, change your RSS subscription to: http://www.shaneandcasey.com/category/house/feed/ I&#8217;ve been looking for a clean solution to having a dynamic connection string for a LINQ to SQL data context. My primary desire for this is developing/debugging an application on [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Note: </strong>If you are subscribed to our blog for house related content, and would prefer not to read nerd-speak, change your RSS subscription to: http://www.shaneandcasey.com/category/house/feed/</p></blockquote>
<p>I&#8217;ve been looking for a clean solution to having a dynamic connection string for a LINQ to SQL data context. My primary desire for this is developing/debugging an application on a test database. Sure, you can always go change your connection string in the app.config file, but I tend to forget to revert it back before deployment.</p>
<p>After doing a bit of research today, I realized that if you open up the project&#8217;s property pages, click on the settings tab, and then click on &#8216;View Code&#8217; on the top, you&#8217;ll access the &#8220;base&#8221; partial Settings class. In the constructor, add an event handler for the SettingsLoaded event handler:<br />
[code lang="csharp"]this.SettingsLoaded += new System.Configuration.SettingsLoadedEventHandler(Settings_SettingsLoaded);[/code]<br />
Then you can set up the event handler in a similar manner:<br />
[code lang="csharp"]///<br />
/// Dynamically update settings for development when a debugger is attached<br />
///<br />
void Settings_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e)<br />
{<br />
    if (System.Diagnostics.Debugger.IsAttached)<br />
    {<br />
        // Adjust the connection string as you see fit<br />
        this[&quot;yourConnectionStringName&quot;] = &quot;Data Source=yourDevHost;Initial Catalog=yourDevDatabase;Persist Security Info=True;User ID=yourDevUser;Password=yourDevPassword&quot;;<br />
    }<br />
}[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaneandcasey.com/2009/05/27/linq-to-sql-dynamic-connection-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

