<?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: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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>managed data</title>
	
	<link>http://www.nielsberglund.com</link>
	<description>Technology musings about SQL Server &amp; CLR / .NET</description>
	<lastBuildDate>Sat, 03 Nov 2012 05:07:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ManagedData" /><feedburner:info uri="manageddata" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>SqlClrProject on GitHub</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/AgjoXSLBwLY/</link>
		<comments>http://www.nielsberglund.com/sql/sqlclr/sqlclrproject-on-github/#comments</comments>
		<pubDate>Sat, 03 Nov 2012 05:07:45 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLCLR]]></category>
		<category><![CDATA[SQLCLRProject]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=295</guid>
		<description><![CDATA[As some of you may know, I &#8211; once upon a time &#8211; developed a project (VS add-in, templates, etc) for automatic deployment of CLR assemblies to SQL Server: SqlClrProject....]]></description>
			<content:encoded><![CDATA[<p>As some of you may know, I &#8211; once upon a time &#8211; developed a project (VS add-in, templates, etc) for automatic deployment of CLR assemblies to SQL Server: <strong>SqlClrProjec</strong>t. That project has been dormant now for a couple of years, but I now and then get requests for where it can be downloaded from (I had it on CodePlex, but had to take it down as I didn&#8217;t publish the source code).</p>
<p>A while ago I decided to start to use Git and GitHub as source control (I have been using SVN since forever), and as part of the &#8220;getting to grips&#8221; with Git, I created a repo for <strong>SqlClrProject</strong> on GitHub. So the source for the project is now available on <a href="https://github.com/nberglund/sqlclrproject">GitHub</a>. (<a href="https://github.com/nberglund/sqlclrproject">https://github.com/nberglund/sqlclrproject</a>)</p>
<p>If you are interested in the  fork it, play with it. The state of it is that it &#8220;should&#8221; work on VS 2008 / SQL 2008. It most likely will work on VS 2010 as well. And of course the standalone deployment executable will work regardless of VS version.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=AgjoXSLBwLY:SuC_z-4kPgg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=AgjoXSLBwLY:SuC_z-4kPgg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=AgjoXSLBwLY:SuC_z-4kPgg:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/AgjoXSLBwLY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/sql/sqlclr/sqlclrproject-on-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/sql/sqlclr/sqlclrproject-on-github/</feedburner:origLink></item>
		<item>
		<title>First Impressions Microsoft BUILD &amp; Win 8</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/46q4VS-ZJoU/</link>
		<comments>http://www.nielsberglund.com/clr/first-impressions-microsoft-build-win-8/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 20:18:59 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[CLR / .NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[BUILD]]></category>
		<category><![CDATA[Win 8]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=286</guid>
		<description><![CDATA[I have a while ago just finished watching the live stream of the first keynote (yes there will be one tomorrow as well), at Microsoft BUILD. Having attended / presented,...]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-medium wp-image-290 aligncenter" title="Sinofsky-Featured-Image" src="http://www.nielsberglund.com/wp-content/uploads/2011/09/AXG02-MICROSOFT_1319274cl-8-300x168.jpg" alt="" width="300" height="168" /></p>
<p>I have a while ago just finished watching the live stream of the first keynote (yes there will be one tomorrow as well), at Microsoft BUILD. Having attended / presented, at quite a few of these kind of events &#8211; and being somewhat jaded (well OK then, a lot jaded), I must still say that I am impressed.</p>
<p>As quite a few other developers I have been fairly worried about what will happen when Win 8 comes; .NET/WPF/SilverLight is dead &#8211; long live HTML etc., but at least for now it seems that the fears have been un-founded. I.e, the .NET as we know and love is still there, SilverLight as well (come to think about it, nothing much was said about WPF). And it seems pretty straightforward to build the new &#8220;Metro&#8221; style apps using the tools we know.</p>
<p>What do I think then: well, Win 8 promises to be really, really slick and cool &#8211; but we have been here before (Longhorn anyone?), so let&#8217;s wait and see until we get to RC stages. However, the whole Win RT, i.e the underlying &#8220;goo&#8221; of Windows (graphics, networking, etc) being exposed to all different types of programming languages; native, .NET, HTML/JavaScript, etc., seems very, very cool. I can&#8217;t wait to getmy hands on some bits and start playing around with this. Speaking of that; bits will apparently be released later at: http://bit.ly/nX2K3a.</p>
<p>So at this stage I am fairly optimistic, and I would not rule out, myself running Win 8 on a couple of machines here at home. I am looking forward to the keynote tomorrow, where they will talk more about the development experience, and hopefully drill deeper into Visual Studio.Next.</p>
<p>Having finally seen the session-list, there are some really interesting sessions during the week. I really, really hope these ones will be videoed:</p>
<ul>
<li><strong>F# 3.0: data, services, Web, cloud, at your fingertips, by Don &#8220;Mr F#&#8221; Syme</strong>: bit.ly/n16Xyu</li>
<li><strong>What&#8217;s new in .NET Framework 4.5</strong>: bit.ly/n7tUKU</li>
<li><strong>Lessons learned designing the Windows Runtime</strong>: bit.ly/pd3XZN</li>
<li><strong>Deep dive into the kernel of the .NET Framework</strong>: http://bit.ly/nX5czN</li>
<li><strong>Using the Windows Runtime from C++</strong>: http://bit.ly/r8Iyq8</li>
<li><strong>Using the Windows Runtime from C# and Visual Basic</strong>: http://bit.ly/r4Q1cT</li>
</ul>
<p>That&#8217;s all for now &#8220;folks&#8221;. Will hopefully post more as the week and the conference goes by.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=46q4VS-ZJoU:pRqL5Ca1JNQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=46q4VS-ZJoU:pRqL5Ca1JNQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=46q4VS-ZJoU:pRqL5Ca1JNQ:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/46q4VS-ZJoU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/clr/first-impressions-microsoft-build-win-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/clr/first-impressions-microsoft-build-win-8/</feedburner:origLink></item>
		<item>
		<title>Transactions in SQL Server (take 2956)</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/TTUjndGaHkk/</link>
		<comments>http://www.nielsberglund.com/sql/transactions-in-sql-server-take-2956/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 18:20:31 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[denali]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=266</guid>
		<description><![CDATA[Transactions in SQL Server seems to be a difficult topic to grasp. This weekend I came across a blog-post where the poster showed a &#8220;solution&#8221; to the &#8220;The ROLLBACK TRANSACTION...]]></description>
			<content:encoded><![CDATA[<p>Transactions in SQL Server seems to be a difficult topic to grasp. This weekend I came across a blog-post where the poster showed a &#8220;solution&#8221; to the &#8220;The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION&#8221; error we sometimes see when various stored procedures call each other. The solution (even though it masked out the error in question) did not get it quite right. So I thought I would make a post about the subject.</p>
<h3>Nested Transactions in SQL Server and the Evil @@TRANCOUNT</h3>
<p>In SQL Server we have the @@TRANCOUNT variable which gives us the number of transactions active in the session &#8211; or that&#8217;s at least what we might believe. Take this  extremely simple code:</p>
<pre class="brush: sql; title: ; notranslate">
SET NOCOUNT ON
CREATE TABLE #t (col1 varchar(15))
PRINT @@TRANCOUNT
BEGIN TRAN
PRINT @@TRANCOUNT
INSERT INTO #t VALUES('HELLO')
BEGIN TRAN
PRINT @@TRANCOUNT
INSERT INTO #t VALUES('WORLD')
COMMIT
PRINT @@TRANCOUNT
COMMIT
PRINT @@TRANCOUNT
</pre>
<p>You should see something like this:</p>
<pre class="brush: sql; title: ; notranslate">
0
1
2
1
0
</pre>
<p>I.e. it seems like the transaction count is increasing for each BEGIN TRAN, and decrease with COMMIT. And if you were to <code>SELECT * FROM #t</code> you would see two rows returned. So far so good, so what is wrong with @@TRANCOUNT then? Well, let us change the code slightly (don&#8217;t forget to drop #t if you copy and paste this code):</p>
<pre class="brush: sql; title: ; notranslate">
SET NOCOUNT ON
CREATE TABLE #t (col1 varchar(15))
PRINT @@TRANCOUNT
BEGIN TRAN
PRINT @@TRANCOUNT
INSERT INTO #t VALUES('HELLO')
BEGIN TRAN
PRINT @@TRANCOUNT
INSERT INTO #t VALUES('WORLD')
COMMIT
PRINT @@TRANCOUNT
ROLLBACK
PRINT @@TRANCOUNT
</pre>
<p>If you now were to (don&#8217;t do it immediately) <code>SELECT * FROM #t</code>, how many rows would you get back &#8211; 0, 1, or 2? Seeing how the @@TRANCOUNT is increasing with every BEGIN TRAN and decreasing with COMMIT / ROLLBACK, it is understandable if your answer is 1:</p>
<ul>
<li>we start a transaction and insert a row</li>
<li>we then start another transaction and insert a second row</li>
<li>we call commit after the second insert (the inner transaction)</li>
<li>finally we do a rollback, on the &#8220;outer&#8221; transaction</li>
</ul>
<p>As we after the second BEGIN TRAN can see @@TRANCOUNT being 2, we could assume that the commit would commit the second insert. However, we all know what happens when we assume  (now would be a good time to do the SELECT)  &#8230;.</p>
<p>Right, the SELECT did not return any rows at all, so it is probably fair to say that we did not have multiple transactions, even though @@TRANCOUNT showed us more than one. So, then we might assume (keep in mind what I&#8217;ve said about assume) that the reason we rolled back was because ROLLBACK was the last statement. Let us switch the COMMIT on line 10 with the ROLLBACK on line 12 (we now have ROLLBACK on line 10 and COMMIT on line 12) and execute. WHOA &#8211; we got a big fat exception, what happened here? To answer that, let us look a bit closer at the main parts of transaction control in your code.</p>
<h3>BEGIN TRAN, COMMIT and ROLLBACK</h3>
<p>When you execute BEGIN TRAN in T-SQL, SQL will look around in the execution context of your session and see if there already exists a transactional context. If not, SQL will start a new transaction. If there is a transaction already, SQL will enlist in this transaction. However in both cases SQL will increase the @@TRANCOUNT variable.</p>
<p>Then, when you execute a COMMIT, SQL will not immediately commit the transaction but will decrease the transaction count with 1. If the transaction count has reached 0 due to the commit, a commit will take place. OK, so far so good, but this does not explain the error we received when switching the COMMIT and ROLLBACK statements, if it works as described, then we should have committed?</p>
<p>Ah, yes &#8211; however, a ROLLBACK not only decrements the transaction count &#8211; it sets it to 0 immediately, and as the transaction count is now 0, a rollback will happen. So in our second example we are seeing something similar to when we &#8211; in stored procs &#8211; are getting the &#8221;The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION&#8221; error.</p>
<h3>Stored Procedures and Transactions</h3>
<p>It is quite common to write procs something like so:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE PROC sp2
AS
SET NOCOUNT ON
BEGIN TRAN
BEGIN TRY
  -- do some stuff
  -- then if all is OK we commit
  COMMIT TRAN
  RETURN 0;
END TRY
BEGIN CATCH
  DECLARE @errMSg varchar(max);
  SELECT @errMSg = ERROR_MESSAGE()
  ROLLBACK TRAN
  RETURN 999; --things have gone very wrong
END CATCH
</pre>
<p>Then we are having a similar proc, looking almost the same, but it, in addition, calls into sp2:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE PROC sp1
AS
SET NOCOUNT ON
BEGIN TRAN
BEGIN TRY
  -- do some stuff
  -- do some more stuff by calling into sp2
  EXEC sp2;
  -- then if all is OK we commit
  COMMIT TRAN
  RETURN 0;
END TRY
BEGIN CATCH
  DECLARE @errMSg varchar(max);
  SELECT @errMSg = ERROR_MESSAGE()
  ROLLBACK TRAN
  RETURN 999; --things have gone very wrong
END CATCH
</pre>
<p>This is now when we will potentially see the error mentioned before. We call sp1, when sp1 is called there is no transactional context around, so SQL creates a new transaction. Then we go on to call sp2 from sp1. In the BEGIN TRAN call in sp2, there exists a transactional context, so SQL enlists us in that context.</p>
<p>If all now goes well and we call COMMIT in sp2, the commit causes the transaction count to be decreased to 1 &#8211; but no &#8220;real&#8221; commit happens. So when we subsequently calls COMMIT in sp1, we decrement the transaction count to 0, and we are committed.</p>
<p>In the case when things go wrong is sp2 and we call rollback, the transaction count is immediately set to 0, and a rollback happens. When we come back to sp1, SQL sees that we had a transaction in sp1, but there are no transactions around, and we will get the error discussed. If we then go on and do a rollback (as in our code) &#8211; we will get additional errors.</p>
<h3>Solution</h3>
<p>A solution to the problem is to use the &#8220;evil&#8221; @@TRANCOUNT, to see if there are any transactions around. If there aren&#8217;t any, we start a transaction. If there are a transaction already, we don&#8217;t do anything, and we let the existing transaction handle everything:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE PROC sp2
AS
DECLARE @tranCount int = @@TRANCOUNT; --I'm using SQL2008 here
SET NOCOUNT ON
IF(@tranCount = 0) --no tx's around, we can start a new
  BEGIN TRAN
BEGIN TRY
  -- do some stuff
  -- then if all is OK we commit
  --if the variable @tranCount is 0,
  -- we have started the tx ourselves, and can commit
  IF(@tranCount = 0 AND XACT_STATE() = 1) --XACT_STATE - just to be on the safe side
    COMMIT TRAN;

  RETURN 0;
END TRY
BEGIN CATCH
  DECLARE @errMSg varchar(max);
  SELECT @errMSg = ERROR_MESSAGE()
  --if the variable @tranCount is 0,
  -- we have started the tx ourselves, and can rollback
  IF(@tranCount = 0 AND XACT_STATE() &lt;&gt; 0) --XACT_STATE - just to be on the safe side
    ROLLBACK TRAN;

  --tell an eventual calling proc that things have gone wrong
  --and the calling proc should rollback
  RETURN 999;
END CATCH
</pre>
<p>Obviously the calling proc would have similar code to decide if to start a tran or not.</p>
<p>In the above scenario we let the &#8220;outer&#8221; proc handle all the transactional control. Sometimes you are in a situation where &#8211; if things go wrong in the &#8220;inner&#8221; proc (sp2 in our case) &#8211; you do not want to roll back everything done, but only what was done in the inner proc. For such a scenarion, you can use named savepoints:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE PROC sp2
AS
DECLARE @tranCount int = @@TRANCOUNT; --I'm using SQL2008 here
SET NOCOUNT ON
IF(@tranCount = 0) --no tx's around, we can start a new
  BEGIN TRAN
ELSE --we are already in a tx, take a savepoint here
  SAVE TRANSACTION sp2 --this is just a name

BEGIN TRY
  -- do some stuff
  -- then if all is OK we commit
  --if the variable @tranCount is 0,
  -- we have started the tx ourselves, and can commit
  IF(@tranCount = 0 AND XACT_STATE() = 1) --XACT_STATE - just to be on the safe side
    COMMIT TRAN;

  RETURN 0;
END TRY
BEGIN CATCH
  DECLARE @errMSg varchar(max);
  SELECT @errMSg = ERROR_MESSAGE()
  --if the variable @tranCount is 0,
  -- we have started the tx ourselves, and can rollback
  IF(@tranCount = 0 AND XACT_STATE() != 0) --XACT_STATE - just to be on the safe side
    ROLLBACK TRAN;
  ELSE IF (@tranCount &gt; 0 AND XACT_STATE != -1)
    ROLLBACK TRANSACTION sp2 --we are rolling back to the save-point

  --tell an eventual calling proc that things have gone wrong
  --and let the calling proc decide what to do with its parts
  RETURN 999;
END CATCH
</pre>
<p>Personally, I do not use named save-points that much as they cannot be used together with linked servers, and we &#8211; unfortunately &#8211; are using linked servers a lot.</p>
<p>A final note about named save-points; they are not the same thing as beginning / committing / rolling back a transaction with a name:</p>
<pre class="brush: sql; title: ; notranslate">
SET NOCOUNT ON
CREATE TABLE #t (col1 varchar(15))
BEGIN TRAN t1
INSERT INTO #t VALUES('HELLO')
ROLLBACK TRAN t1
</pre>
<p>Beginning a transaction with a name, is for most parts just a convenience. It has no effect on nesting (unless you use named save points), and SQL Server Books OnLine says this about naming of transactions:<br />
&#8220;Naming multiple transactions in a series of nested transactions with a transaction name has little effect on the transaction. Only the first (outermost) transaction name is registered with the system. A rollback to any other name (other than a valid savepoint name) generates an error. None of the statements executed before the rollback is, in fact, rolled back at the time this error occurs. The statements are rolled back only when the outer transaction is rolled back&#8221;.</p>
<p>If you have questions, observations etc., please feel free to leave me a comment, or drop me an email.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=TTUjndGaHkk:P3zfOxbAnf0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=TTUjndGaHkk:P3zfOxbAnf0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=TTUjndGaHkk:P3zfOxbAnf0:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/TTUjndGaHkk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/sql/transactions-in-sql-server-take-2956/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/sql/transactions-in-sql-server-take-2956/</feedburner:origLink></item>
		<item>
		<title>F#, Mono and Mac – Take II</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/6YDQYJN0KrE/</link>
		<comments>http://www.nielsberglund.com/clr/fsharp-mono-and-mac-2/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 18:40:00 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[CLR / .NET]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=246</guid>
		<description><![CDATA[So yesterday I wrote about how I have started using F# and Mono on my MacBook. I wrote about how I downloaded the F# bits, unzipped and put them in...]]></description>
			<content:encoded><![CDATA[<p>So yesterday <a href="http://www.nielsberglund.com/clr/fsharp-mono-and-mac/" target="_blank">I wrote</a> about how I have started using F# and Mono on my MacBook.</p>
<p>I wrote about how I downloaded the F# bits, unzipped and put them in a specific directory I had created. Today after having browsed around a bit more I realized I had done it the hard way. To install the required bits for F# for Mac, you only have to download a zip file with an install package for Mac from the <a href="http://fsxplat.codeplex.com/" target="_blank">F# Cross Platform</a> site on CodePlex. The actual zip-file for the November 2010 CTP is <a href="http://fsxplat.codeplex.com/releases/view/55463#DownloadId=166558">here</a>.</p>
<p>After you have downloaded the file you unzip it and run the <code>.pkg</code> file. This takes care of everything; no re-signing with the <code>.snk</code> file etc. The added benefit of installing from the <code>.pkg</code> file is that a couple of F# compiler dll&#8217;s are automatically gac:ed (they are needed if you want to run the F# plugin for MonoDevelop), and aliases are created for the F# compiler and the F# interactive window.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=6YDQYJN0KrE:vXDrIIDjoUQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=6YDQYJN0KrE:vXDrIIDjoUQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=6YDQYJN0KrE:vXDrIIDjoUQ:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/6YDQYJN0KrE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/clr/fsharp-mono-and-mac-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/clr/fsharp-mono-and-mac-2/</feedburner:origLink></item>
		<item>
		<title>F#, Mono and Mac</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/ekO6vbD6Mac/</link>
		<comments>http://www.nielsberglund.com/clr/fsharp-mono-and-mac/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 20:40:00 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[CLR / .NET]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=242</guid>
		<description><![CDATA[This is a first post about my experiences with running F# and Mono on a Mac.&#160; In a previous post I wrote about how I have started to play with...]]></description>
			<content:encoded><![CDATA[<p>This is a first post about my experiences with running F# and Mono on a Mac.&nbsp;</p>
<p>In a <a href="http://www.nielsberglund.com/clr/using-fsharp-in-sqlclr/" target="_blank">previous post</a> I wrote about how I have started to play with F#. As that post also covered SQLCLR it was obvious I was on Windows. Even though I make my living from development in a Windows environment, my main machine is a MacBook, and I run OSX as my main OS. I have previously also been running Linux (ArchLinux) on this machine as my main OS.&nbsp;Naturally I have heard about Mono (and also installed it a couple of times &#8211; and quickly un-installed again <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ), but I have not really done anything with it. I have always run Windows in a VM on my MacBook for development etc.&nbsp;However after the announcement that F# was going <a href="http://blogs.msdn.com/b/dsyme/archive/2010/11/04/announcing-the-f-compiler-library-source-code-drop.aspx" target="_blank">Open Source</a>, and <a href="http://tomasp.net/blog/" target="_blank">Tomas P</a> <a href="http://tomasp.net/blog/fsharp-in-monodevelop.aspx" target="_blank">posted about his F# MonoDevelop plug-in</a>, I decided that I should have a look at what it would be like to do F# &#8220;stuff&#8221; in OSX.</p>
<p>This is what I did:</p>
<ol>
<li>Downloaded Mono from <a href="http://www.go-mono.com/mono-downloads/download.html" target="_blank">here</a>.</li>
<li>Downloaded F# from <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=f8c623ae-aef6-4a06-a185-05f59be47d67&amp;displaylang=en" target="_blank">here</a>. You want to download the zip file.</li>
</ol>
<p>Having downloaded what I thought was necessary (I decided to hold off with MonoDevelop until I had&nbsp;everything&nbsp;running), I started the installation process. Installing Mono was straight forward, just mount the <code>.dmg</code> and then run the <code>.pkg</code> file. The only slight issue after installation &nbsp;was where it had been installed. Mostly for my own reference for later installations; Mono is located at: <code>/Library/Frameworks/Mono.framework</code>.</p>
<p>After I had installed Mono, I copied the bin directory from the unzipped F# file to a directory I created in the same root folder as where Mono was: <code>/Library/Frameworks/FSharp</code>. I copied the <code>install-mono.sh</code> file to the FSharp directory and was ready to start the installation. Fortunately before I executed the <code>install-mono.sh</code> file, I read the comments in the file. At this stage I&nbsp;realised&nbsp;I had not downloaded everything necessary.</p>
<p>One of the F# dll&#8217;s <code>FSharp.Core.dll</code> needs to be installed in the gac. In order to do that, the dll needs to be re-signed with the <code>mono.snk</code> key. The installation file mentions how you can download the file using <code>wget</code>. As I did not have <code>wget</code> I found a link to it and downloaded it by right-clicking on the link and choose &#8220;Save Link As &#8230;&#8221;. Once again mostly for my future reference; the file can be found at:&nbsp;<a href="http://github.com/mono/mono/raw/master/mcs/class/mono.snk">http://github.com/mono/mono/raw/master/mcs/class/mono.snk</a>&nbsp;(just right click and choose &#8220;Save Link As &#8230;&#8221;. I saved it into the F# root folder (the same folder where the <code>install-mono.sh</code> is).</p>
<p>So, now everything should be ready to go. I executed the install file and promptly got an error saying that the <code>FSharp.Core.dll</code> could not be installed in the gac. Hmm, not good! Fortunately the error message mentioned something about a possible permission error, so I looked at the permissions on the gac folder (<code>../Mono.framework/Versions/2.8/lib/mono/gac</code>), and sure enough &#8211; I did not have write permissions. I gave myself write permissions, and re-ran the installation and everything went OK. Cool!!</p>
<p>After this it was time to test it out. From the F# bin directory I ran the following from a terminal window to execute the compiler: &lt;code&gt;mono fsc.exe&lt;/code&gt;. It seemed to work as I got this error back:</p>
<p><img src="http://www.nielsberglund.com/wp-content/uploads/2010/11/fsc.exe.png" alt="" width="658" height="178" /></p>
<p>I then tried the interactive window: <code>mono fsi.exe</code>. I wrote some simple test code:</p>
<p><img src="http://www.nielsberglund.com/wp-content/uploads/2010/11/fsi-exec.png" alt="" width="661" height="330" /></p>
<p>As you can see, that worked as well!! So I am now well on the way of running (and learning) F# on Mono. Next step is to install MonoDevelop and Tomas P&#8217;s plugin for F#. Stay tuned &#8230;.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=ekO6vbD6Mac:xZwqB9uUE4M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=ekO6vbD6Mac:xZwqB9uUE4M:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=ekO6vbD6Mac:xZwqB9uUE4M:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/ekO6vbD6Mac" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/clr/fsharp-mono-and-mac/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/clr/fsharp-mono-and-mac/</feedburner:origLink></item>
		<item>
		<title>TPL Dataflow, Axum v.NEXT?</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/s2GMaElAf88/</link>
		<comments>http://www.nielsberglund.com/clr/tpl-dataflow-axum-v-next/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 19:33:54 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[CLR / .NET]]></category>
		<category><![CDATA[Async / Parallel]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[tpl]]></category>
		<category><![CDATA[tpldataflow]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=235</guid>
		<description><![CDATA[At PDC 2010 Microsoft showed the new Async features of coming C# (and VB.NET) versions, and quite a lot has been written about it already. Part of the Async CTP...]]></description>
			<content:encoded><![CDATA[<p>At PDC 2010 Microsoft showed the new <a href="http://msdn.microsoft.com/en-us/vstudio/async.aspx" target="_blank">Async</a> features of coming C# (and VB.NET) versions, and quite a lot has been written about it already. Part of the Async CTP is TPL Dataflow, and this has gone somewhat un-noticed.</p>
<p><a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d5b3e1f8-c672-48e8-baf8-94f05b431f5c&amp;displaylang=en" target="_blank">TPL Dataflow</a> is a library for building concurrent applications. It utilises an actor/agent-oriented designs via primitives for in-process message passing, dataflow, and pipelining. It looks and feels a bit like <a href="http://msdn.microsoft.com/en-us/devlabs/dd795202.aspx" target="_blank">Axum</a>, and one can wonder if TPL Dataflow will be the productization (is this a word?) of Axum, especially as Axum&#8217;s future seems a bit <a href="http://social.msdn.microsoft.com/Forums/en-US/axum/thread/f86881de-71af-4709-b197-64a6e6dc96dd" target="_blank">unclear</a> at the moment.</p>
<p>I am at the moment writing some test-code for TPL Dataflow, which I will post as soon as I have tidied it up a bit. In the meantime <a href="http://mdavey.wordpress.com/" target="_blank">Matt Davey</a>, have a quite a few <a href="http://en.wordpress.com/tag/tpldataflow/" target="_blank">posts about TPL Dataflow</a> on his blog. So if you are interested, go and have a look.</p>
<hr /><em>Subscribe to my RSS feed: <a href="http://feeds.feedburner.com/manageddata" target="_blank">http://feeds.feedburner.com/manageddata</a></em>.<br />
<em>Follow me on twitter as: <a href="http://twitter.com/nielsberglund" target="_blank">@nielsberglund</a></em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=s2GMaElAf88:vefeyQaEj_Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=s2GMaElAf88:vefeyQaEj_Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=s2GMaElAf88:vefeyQaEj_Y:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/s2GMaElAf88" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/clr/tpl-dataflow-axum-v-next/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/clr/tpl-dataflow-axum-v-next/</feedburner:origLink></item>
		<item>
		<title>Using F# in SQLCLR</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/l1i3YMwSzG4/</link>
		<comments>http://www.nielsberglund.com/clr/using-fsharp-in-sqlclr/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 21:05:26 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[CLR / .NET]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[SQLCLR]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=218</guid>
		<description><![CDATA[Recently I have become very interested in F# and I am at the moment trying to get to grips with it. It is definitely a different beast than C#, but...]]></description>
			<content:encoded><![CDATA[<p>Recently I have become very interested in F# and I am at the moment trying to get to grips with it. It is definitely a different beast than C#, but so far I like it &#8211; a lot!</p>
<p>Anyway, I am a SQL nerd, and many moons ago I was very heavily involved in SQLCLR (for you who don&#8217;t know what that is; it is the ability to run .NET code inside the SQL Server engine. It was firat introduced with SQL Server 2005). So I thought it would be a &#8220;giggle&#8221; to see if I could get some F# code running inside SQL Server.</p>
<p>I created the simplest of the simple F# dll&#8217;s. SQLCLR requires you have a public class and your publicly exposed SQLCLR methods to be static, so my F# code looked like so:</p>
<pre class="brush: fsharp; title: ; notranslate">
namespace ManagedData.Samples.FSharp
  type SqlClr =
    static member Adder a b = a + b
    static member Factorial n =
      match n with
      | 0  -&gt; 1
      | _ -&gt; n * (SqlClr.Factorial( n - 1))
</pre>
<p>As you can see my class is extremely advanced (not); it has two methods:</p>
<ul>
<li>The canonical Adder method (every SQLCLR dll has to have an Adder method, it&#8217;s the law &#8211; nah, I&#8217;m just kidding <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ), which takes two integers and returns an integer.</li>
<li>A factorial method, which takes an integer and calculates the factorial from that.</li>
</ul>
<p>By the way, any pointers about how to write efficient F# code are very welcome .</p>
<p>Having written and compiled the code, it was time to deploy! When running .NET code in SQL Server, you need to deploy your assembly to the database you want to execute your code in, and SQL Server will actually load the assembly from the database. In fact most assemblies are loaded from the database, even quite a few of Microsoft&#8217;s own system assemblies which normally are loaded from the GAC. There are only about 13 system assemblies that are allowed to be loaded from the GAC &#8211; these are known as the &#8220;blessed list&#8221;. You also need to create T-SQL wrapper objects (procedures, functions, triggers, etc.) around the methods you want to publicly expose.</p>
<p>In my SQL Server 2008R2 instance I created a database in which I wanted my F# assembly to, and then it was time to deploy. You can deploy in several ways, the easiest is something like this (in the database you want to use):</p>
<pre class="brush: sql; title: ; notranslate">
CREATE ASSEMBLY fsasm
FROM 'c:\repos\F#\testcode\fssqlclr\fslib\bin\debug\fslib.dll'
WITH permission_set = SAFE;
GO
</pre>
<p>The problem with the code above is that F# projects have a dependency on the assembly <code>FSharp.Core.dll</code>, so when I tried to deploy my assembly as per above, I got an exception. What I had to do was to deploy <code>FSharp.Core.dll</code> to my database first:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE ASSEMBLY fsasm
FROM 'C:\path to ...\FSharp.Core.dll'
WITH permission_set = UNSAFE;
GO
</pre>
<p>Notice the use of <code>permission_set = UNSAFE</code>, this is to tell SQL Server that I know what I am doing <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and SQL Server should keep from doing a lot if validation. When I had catalogued the <code>FSharp.Core.dll</code> assembly I had no problems deploying my assembly to the database.</p>
<p>All there remained to do now was to create the T-SQL wrapper object(s) around my F# methods. This is done with &#8220;normal&#8221; <code>CREATE ...</code> syntax. The code for my factorial looks like so:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE FUNCTION FsFactorial(@x int)
RETURNS int
EXTERNAL NAME fsasm.[ManagedData.Samples.FSharp.SqlClr].Factorial;
GO
</pre>
<p>This also went without problems, so now it is &#8220;crunch-time&#8221;. Can I execute a F# method in SQLCLR?</p>
<pre class="brush: sql; title: ; notranslate">
SELECT dbo.FsFactorial(4);
</pre>
<p>Lo and behold, it executed and I received 24 back! I had just now executed F# running inside SQL Server!!</p>
<p>So, what does this prove? Nothing really <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , it was just an exercise from me to see if it could be done. However, F# is really suitable for quite a few tasks you would want to use SQLCLR for, so it now gives a database developer another tool in his tool-belt.</p>
<p>If anyone is interested in the full code for this, please drop me a comment and I&#8217;ll email it to you.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=l1i3YMwSzG4:u__zVRtTmI8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=l1i3YMwSzG4:u__zVRtTmI8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=l1i3YMwSzG4:u__zVRtTmI8:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/l1i3YMwSzG4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/clr/using-fsharp-in-sqlclr/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/clr/using-fsharp-in-sqlclr/</feedburner:origLink></item>
		<item>
		<title>SQL Server Denali CTP 1 SUX ….</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/_tTjHC_a1N8/</link>
		<comments>http://www.nielsberglund.com/sql/sql-server-denali-ctp-1-sux/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 12:07:11 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[denali]]></category>
		<category><![CDATA[SQL 11]]></category>
		<category><![CDATA[SQLCLR]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=215</guid>
		<description><![CDATA[.. from a relational developers perspective!! Well, the title may be a bit harsh, but at least it grabbed your attention &#8211; did it not?! A week ago, or so,...]]></description>
			<content:encoded><![CDATA[<p>.. from a relational developers perspective!!</p>
<p>Well, the title may be a bit harsh, but at least it grabbed your attention &#8211; did it not?! <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>A week ago, or so, I wrote a <a href="http://www.nielsberglund.com/sql/what-new-programmability-features-will-there-be-in-sql-11/">wish list</a> to Santa for Denali from a relational developers perspective. In that wish list I wrote that there has been fairly little love for relational SQL developers in the recent versions of SQL Server, and that I hoped in this version (i.e Denali) Microsoft would &#8220;go back to the roots&#8221; and give us developers some new stuff.</p>
<p>So I downloaded the CTP when it became available, and have been playing around with it for a bit, in order to see what new &#8220;stuff&#8221; I could find and how it stacked up against my wish list:</p>
<ul>
<li>Autonomous transactions &#8211; not a whiff of it <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </li>
<li>Enhancements to SQLCLR &#8211; Denali is still loading version 2.0.50727 of the runtime (i.e. the original &#8211; SQL 2005 &#8211; version). So nothing here either, and they have not even added Microsoft.SqlServer.Types (for the geo and hierarchy types) to the blessed list. This (lack of SQLCLR enhancements) is probably the one thing that saddens me the most &#8211; it seems that after all the initial hoopla and fanfare about SQLCLR when it was introduced in SQL Server 2005, Microsoft has decided to not fullfil its potentials. <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  <img src='http://www.nielsberglund.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </li>
<li>Finally blocks &#8211; well, we do not have finally blocks but we now have a proper way of throwing and re-throwing exceptions; the <code>THROW</code> keyword. I wrote about it <a href="http://www.nielsberglund.com/sql/new-t-sql-features-in-sql-11-denali-error-handling/">here</a> and <a href="http://www.nielsberglund.com/sql/more-t-sql-error-functionality-in-denali-sql-11/">here</a>. So at least this is something.</li>
<li>Other T-SQL enhancements &#8211; this is an area where there are at least a couple of new things: <code>SEQUENCE</code> and <code>OFFSET</code>. Those are cool and useful and Aaron B wrote about them <a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/11/sql-server-11-denali-using-sequence.aspx">here</a> and <a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/10/sql-server-11-denali-using-the-offset-clause.aspx">here</a>. But this is still not very much, and no evidence of that Microsoft want to continue to enhance T-SQL as a first class development language (as they have stated in the past).</li>
</ul>
<p>So, the report card does not look that good and that&#8217;s the reason for the title of this post. Granted, there are things that are in the cards but not included in this CTP; things like:</p>
<ul>
<li>Column storage &#8211; however, that is more a BI feature, but it will be usable in the OLTP world as well.</li>
<li>FileTable &#8211; a way of storing files in SQL Server. It looks like FileStream v.NEXT or (do I dare say it) WinFS (now I have most certainly condemned this to death). It looks interesting, but &#8211; as I said &#8211; not in this CTP.</li>
</ul>
<p>As you can gather from the above, I am not that stoked about Denali. I hope later CTP&#8217;s will bring more things, but somehow I doubt it.</p>
<p>What are your take on this, are you happy with what Denali gives you (from a relational developers perspective), and if not &#8211; what would you like to see included. Answers in the comments please.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=_tTjHC_a1N8:MVjzv4HftcE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=_tTjHC_a1N8:MVjzv4HftcE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=_tTjHC_a1N8:MVjzv4HftcE:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/_tTjHC_a1N8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/sql/sql-server-denali-ctp-1-sux/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/sql/sql-server-denali-ctp-1-sux/</feedburner:origLink></item>
		<item>
		<title>Beginners F# Resources</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/a_DXlPZoMdE/</link>
		<comments>http://www.nielsberglund.com/clr/beginners-fsharp-resources/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 19:40:00 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[CLR / .NET]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=211</guid>
		<description><![CDATA[This post is more as a reminder to myself where to find online resources when learning F#. If anyone else can find it useful, so much better. And, if anyone...]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: small;">This post is more as a reminder to myself where to find online resources when learning F#. If anyone else can find it useful, so much better. And, if anyone out there has other online &nbsp;resources, please leave a comment and I will include it. So, in no particular order:</span></p>
<ul>
<li><span style="font-size: small;"><a href="http://msdn.microsoft.com/en-us/magazine/ff714588.aspx">http://msdn.microsoft.com/en-us/magazine/ff714588.aspx</a></span> &#8211; Introductory article by Luke Hoban in MSDN Magazine.</li>
<li><a href="http://www.ctocorner.com/fsharp/book/">http://www.ctocorner.com/fsharp/book/</a> &#8211; As the url says, an online book about F#. <a href="http://blogs.msdn.com/b/dsyme/archive/2010/11/13/getting-started-with-f-online.aspx">Recommended </a>by Mr. F# (Don Syme).</li>
<li><a href="http://www.jelovic.com/weblog/?p=215">http://www.jelovic.com/weblog/?p=215</a> &#8211; Tutorial, by Dejan Jelovic, about getting started with F# from a C# developers perspective.</li>
<li><a href="http://lorgonblog.wordpress.com/2009/05/16/brians-favorite-online-content-for-learning-f/" target="_blank">http://lorgonblog.wordpress.com/2009/05/16/brians-favorite-online-content-for-learning-f/</a> &#8211; Brian McNamara has great info and resource list, highly recommended</li>
</ul>
<p><span style="font-size: small;"><span style="line-height: 24px;">Finally, a list like this would be incomplete without the link to the Man himself: Don Syme; <a href="http://blogs.msdn.com/b/dsyme/">http://blogs.msdn.com/b/dsyme/</a></span></span></p>
<p><span style="font-size: small;"><strong><span style="line-height: 24px;">UPDATE: </span></strong><span style="line-height: 24px;">added Brian McNamara to the list November 26 (I don&#8217;t know how I missed him initially)</span></span></p>
<p>&nbsp;</p>
<hr />
<p><em>You can subscribe to my RSS feed at: <a href="http://feeds.feedburner.com/manageddata">http://feeds.feedburner.com/manageddata</a>.<br />
 I am also at twitter as <a href="http://twitter.com/nielsberglund">@nielsberglund</a></em></p>
<p>&nbsp;</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=a_DXlPZoMdE:h569XEuDuP0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=a_DXlPZoMdE:h569XEuDuP0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=a_DXlPZoMdE:h569XEuDuP0:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/a_DXlPZoMdE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/clr/beginners-fsharp-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/clr/beginners-fsharp-resources/</feedburner:origLink></item>
		<item>
		<title>More T-SQL Error Functionality in Denali / SQL 11</title>
		<link>http://feedproxy.google.com/~r/ManagedData/~3/66tzix8iMNE/</link>
		<comments>http://www.nielsberglund.com/sql/more-t-sql-error-functionality-in-denali-sql-11/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 17:57:00 +0000</pubDate>
		<dc:creator>nielsb</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[denali]]></category>
		<category><![CDATA[SQL 11]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://www.nielsberglund.com/?p=197</guid>
		<description><![CDATA[In my previous post I wrote about the new THROW keyword in Denali / SQL 11. Having played around a bit more with Denali, I wanted to write some additional...]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="http://www.nielsberglund.com/sql/new-t-sql-features-in-sql-11-denali-error-handling/">post</a> I wrote about the new <code>THROW</code> keyword in Denali / SQL 11. Having played around a bit more with Denali, I wanted to write some additional things about <code>THROW</code> and it&#8217;s relation to <code>RAISERROR</code>.</p>
<h3>RAISERROR</h3>
<p>First some background / overview of RAISERROR:</p>
<ul>
<li>RAISERROR allows you to throw an error based on either an error number or a message, and you can define the severity level and state of that error:</p>
<pre class="brush: sql; title: ; notranslate">
 RAISERROR(50001, 16, 1);
 --or
 RAISERROR('Ooops', 16, 1);
 </pre>
</li>
<li>If you call <code>RAISERROR</code> with an error number, that error number has to exist in sys.messages.</li>
<li>You can use error numbers between 13001 and 2147483647 (it cannot be 50000) with  <code>RAISERROR</code>.</li>
</ul>
<p>As I mentioned in my previous <a href="http://www.nielsberglund.com/sql/new-t-sql-features-in-sql-11-denali-error-handling/">post</a>, <code>RAISERROR</code> has been around since forever &#8211; and it works fairly well. One of the major drawbacks with <code>RAISERROR</code> &#8211; as I also wrote in my previous post &#8211; is that it cannot be used to re-throw an error we might have trapped in a structured error handling block. Or rather, this may not be that much a <code>RAISERROR</code> issue, as an issue that SQL Server has not previously supported the notion of re-throwing an error. Be as it may with that, there are other drawbacks with <code>RAISERROR</code> which I will mention later in this post.</p>
<h3>THROW</h3>
<p>In Denali / SQL 11 Microsoft introduces the <code>THROW</code> keyword, which allows us to re-throw an exception caught in an exception handling block. Some characteristics of <code>THROW</code>:</p>
<ul>
<li>Using <code>THROW</code> you can throw a specific error number as well as message:</p>
<pre class="brush: sql; title: ; notranslate">THROW 50000, 'Ooops', 1;</pre>
</li>
<li>When using <code>THROW&gt;</code> you have to define both an error number as well as a message (and state), unless you re-throw an exception.</li>
<li>The error number does not have to exist in sys.messages but, it has to be between 50000 and 2147483647.</li>
</ul>
<p>So, <code>THROW</code> looks fairly cool, but what are the drawbacks with <code>RAISERROR</code> I mentioned above? <span style="text-decoration: line-through;">Well, for one &#8211; beginning with Denali / SQL 11 <code>RAISERROR</code> is being deprecated, i.e. it will eventually be removed from SQL Server</span>. Another reason has to do with transactions and error handling.</p>
<p><strong>UPDATE:</strong>&nbsp;&nbsp;According to <a href="http://sqlblog.com/blogs/aaron_bertrand/" target="_blank">Aaron Bertrand</a>, in his post <a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/22/sql-server-v-next-denali-using-throw-instead-of-raiserror.aspx" target="_blank">here</a>, it is only some very old RAISERROR syntax that is being deprecated.&nbsp;</p>
<h3>XACT_ABORT</h3>
<p>As every T-SQL programmer worth his (or her) salt should know, an exception does not roll back a transaction by default (ok, ok, it does depend on severity level to an extent &#8211; but a &#8220;normal&#8221; exception does not roll back a tran). I.e. the following code would cause two rows to be inserted in the table <code>t1</code>:</p>
<pre class="brush: sql; title: ; notranslate">
 --first create a test table which we will use throughout the code samples
 CREATE TABLE t1 (id int primary key, col1 nvarchar(15));
 --now onto the 'meat'
 BEGIN TRAN
 INSERT INTO t1 VALUES(1, 'row1');
 --emulate some error, this will indeed cause an exception to happen,
 --but the processing will continue
 SELECT 1 / 0
 INSERT INTO t1 VALUES(2, 'row2')
 COMMIT
 </pre>
<p>We can indicate to SQL Server that we want &#8220;automatic&#8221; rollback of transactions when an exception happens &nbsp;by setting <code>XACT_ABORT</code>. This will cause a rollback to happen if a system exception happens. So based on the example above, no rows will be inserted when the code below executes:</p>
<pre class="brush: sql; title: ; notranslate">
 SET XACT_ABORT ON
 BEGIN TRAN
 INSERT INTO t1 VALUES(3, 'row3');
 SELECT 1 / 0
 INSERT INTO T1 VALUES(4, 'row4')
 COMMIT
 </pre>
<p>However, what happens if the user throws an exception using <code>RAISERROR</code>? In that case no rollback happens, i.e. <code>RAISERROR</code> does not honor the <code>XACT_ABORT</code> setting:</p>
<pre class="brush: sql; title: ; notranslate">
 SET XACT_ABORT ON
 BEGIN TRAN
 INSERT INTO t1 VALUES(5, 'row5');
 --the user raises an error, but the tx will not roll back
 RAISERROR('Oooops', 16, 1)
 INSERT INTO t1 VALUES(6, 'row6')
 COMMIT
 </pre>
<p>This can catch developers out and is in my opinion a fairly severe drawback. So with the introduction of Denali / SQL 11 and the <code>THROW</code> keyword, Microsoft has tried to fix this by making <code>THROW</code> honor <code>XACT_ABORT</code>:</p>
<pre class="brush: sql; title: ; notranslate">
 SET XACT_ABORT ON
 BEGIN TRAN
 INSERT INTO t1 VALUES(7, 'row7');
 --the user raises an error, and the tx will roll back
 THROW 50000, 'Ooops', 1
 INSERT INTO t1 VALUES(8, 'row8')
 COMMIT
 </pre>
<p>When you run the code above, you will see that the transaction is indeed rolled back and no rows are inserted.</p>
<p>So developers, &#8220;go forth&#8221; and <code>THROW</code> exceptions in SQL Server Denali / SQL 11.</p>
<p>&nbsp;</p>
<hr />
<p><em>You can subscribe to my RSS feed at: <a href="http://feeds.feedburner.com/manageddata">http://feeds.feedburner.com/manageddata</a>.</em></p>
<p>&nbsp;</p>
<p><em>I am also at twitter as <a href="http://twitter.com/nielsberglund">@nielsberglund</a></em></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ManagedData?a=66tzix8iMNE:7JFPNjk6DXg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ManagedData?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ManagedData?a=66tzix8iMNE:7JFPNjk6DXg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ManagedData?i=66tzix8iMNE:7JFPNjk6DXg:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ManagedData/~4/66tzix8iMNE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nielsberglund.com/sql/more-t-sql-error-functionality-in-denali-sql-11/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.nielsberglund.com/sql/more-t-sql-error-functionality-in-denali-sql-11/</feedburner:origLink></item>
	</channel>
</rss><!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
