<?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>Eric Fickes &#187; .net</title>
	<atom:link href="http://ericfickes.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://ericfickes.com</link>
	<description>Internets, Databases, Skateboards, Ice Hockeys, and Family</description>
	<lastBuildDate>Thu, 22 Jul 2010 22:45:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to TWEET from a SQL CLR Stored Procedure</title>
		<link>http://ericfickes.com/2010/03/how-to-tweet-from-a-sql-crl-stored-procedure/</link>
		<comments>http://ericfickes.com/2010/03/how-to-tweet-from-a-sql-crl-stored-procedure/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 01:10:58 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[tsql]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[.net assembly]]></category>
		<category><![CDATA[.net Common Language Runtime]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[CLR SPROC]]></category>
		<category><![CDATA[sproc]]></category>
		<category><![CDATA[sql server 2005]]></category>
		<category><![CDATA[stored procedure]]></category>
		<category><![CDATA[tweet]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1133</guid>
		<description><![CDATA[Here&#8217;s another SQL Server 2005 geek out moment, a CLR SPROC that tweets to Twitter. Big shoutout to Danny Battison for sharing the C# code to post to Twitter. This is what got me started on the C# side of things.  Also, you can skip all my ramblings here and just download code here and [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another SQL Server 2005 geek out moment, a CLR SPROC that tweets to Twitter.  Big shoutout to <a title="Danny Battison is a C# rocker!" href="http://www.dreamincode.net/code/snippet2556.htm" target="_blank">Danny Battison for sharing the C# code to post to Twitter</a>.  This is what got me started on the C# side of things.  Also, you can skip all my ramblings here and just <a title="CLR SPROC &gt; Tweetsproc sample code" href="http://ericfickes.com/code/tweetsproc.zip" target="_blank">download code here</a> and fire it up.  The zip file contains all the source code, the compiled assembly file, and install.sql that shows you how to hook this up.</p>
<p>Being the SQL junky that I am, I was interested in trying out SQL Server&#8217;s new  <a title="CLR Stored Procedures on MSDN" href="http://msdn.microsoft.com/en-us/library/ms131094.aspx" target="_blank">CLR Stored Procedures</a>.  A CLR sproc is a stored procedure that is able to use .net code that you&#8217;ve compiled into an assembly file.  For you classic ASP heads out there, think of the ASP page being the sproc, and the .net assembly being your COM object ( cringe, let&#8217;s talk about classic ASP ).  While there are plenty of great articles on <a title="Writing CLR Stored Procedures on SQLTEAM.com" href="http://www.sqlteam.com/article/writing-clr-stored-procedures-in-charp-introduction-to-charp-part-1" target="_blank">writing CLR stored procedures</a>, I&#8217;m going to breeze through the code that makes up this project.</p>
<h2>First make a .net class library that will be compiled into an assembly file.</h2>
<pre class="brush: csharp;">
using System;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

/// &lt;summary&gt;
/// This assembly will be used by a SQL2005 SPROC to communicate
/// with twitter.com
/// &lt;/summary&gt;
public sealed class tweetsproc
{
    /*
     * TWITTER CODE BORROWED FROM :
     *  http://www.dreamincode.net/code/snippet2556.htm
     *
     * A function to post an update to Twitter programmatically
     * Author: Danny Battison
     * Contact: gabehabe@hotmail.com
     */

    /// &lt;summary&gt;
    /// Post an update to a Twitter acount
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;username&quot;&gt;The username of the account&lt;/param&gt;
    /// &lt;param name=&quot;password&quot;&gt;The password of the account&lt;/param&gt;
    /// &lt;param name=&quot;tweet&quot;&gt;The status to post&lt;/param&gt;
    [Microsoft.SqlServer.Server.SqlProcedure(Name = &quot;PostTweet&quot;)]
    //public static void PostTweet( string username, string password, string tweet)
    public static void PostTweet(   SqlString username,
                                    SqlString password,
                                    SqlString tweet)
    {
        try
        {
            // encode the username/password
            string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username.ToString() + &quot;:&quot; + password.ToString()));
            // determine what we want to upload as a status
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(&quot;status=&quot; + tweet.ToString());

            // Create a WebPermission.
            WebPermission myWebPermission1 = new WebPermission();

            // Allow Connect access to the specified URLs.
            myWebPermission1.AddPermission(NetworkAccess.Connect,new Regex(&quot;http://www\\.twitter\\.com/.*&quot;,
              RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline));

            myWebPermission1.Demand();

            // connect with the update page
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(&quot;http://twitter.com/statuses/update.xml&quot;);

            // set the method to POST
            request.Method = &quot;POST&quot;;
            request.ServicePoint.Expect100Continue = false; // thanks to argodev for this recent change!
            // set the authorisation levels
            request.Headers.Add(&quot;Authorization&quot;, &quot;Basic &quot; + user);
            request.ContentType = &quot;application/x-www-form-urlencoded&quot;;
            // set the length of the content
            request.ContentLength = bytes.Length;

            // set up the stream
            Stream reqStream = request.GetRequestStream();
            // write to the stream
            reqStream.Write(bytes, 0, bytes.Length);
            // close the stream
            reqStream.Close();

            // Let's get the Response from Twitter
            var webresp = request.GetResponse();
            // Let's read the Response
            var sread = new StreamReader( webresp.GetResponseStream() );

            // Use SqlContext to return data to the QueryAnalyzer results window
            SqlContext.Pipe.Send( sread.ReadToEnd() );

        }
        catch (Exception exc)
        {
            // send error back
            SqlContext.Pipe.Send(exc.Message);
        }
    }
}
</pre>
<h3>Here&#8217;s the app.config for this assembly.</h3>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
  &lt;system.web&gt;
    &lt;trust level=&quot;Full&quot; processRequestInApplicationTrust=&quot;true&quot; originUrl=&quot;&quot; /&gt;
  &lt;/system.web&gt;
&lt;/configuration&gt;
</pre>
<p>Once you build this project, you should have your assembly ( tweetsproc.dll ) which will be used by your CLR Sproc.  Now it&#8217;s time to do some SQL server work.</p>
<h2>Enable CLR access for SQL server</h2>
<pre class="brush: sql;">
EXEC sp_configure @configname = 'clr enabled', @configvalue = 1
RECONFIGURE WITH OVERRIDE
GO
</pre>
<h2>Create the SQL Assembly</h2>
<pre class="brush: sql;">
CREATE ASSEMBLY tweetsproc_clr_assembly from 'C:\Users\eric\Desktop\blog\tweetsproc.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS
GO
</pre>
<h2>Create your SPROC</h2>
<pre class="brush: sql;">
CREATE PROC tweetsproc_tweet(	@username as nvarchar(50),
								@password as nvarchar(50),
								@tweet as nvarchar(140)
							)
AS
	-- [Assembly Name].[Class Name].[CLR function Name]
	EXTERNAL NAME tweetsproc_clr_assembly.tweetsproc.PostTweet
GO
</pre>
<h2>Tweet from a sproc</h2>
<pre class="brush: sql;">EXEC tweetsproc_tweet 'TwitterUsername', 'TwitterPassword', 'Hey @ericfickes, I''m tweeting from my database too!'</pre>
<p>Running this sproc returns the XML response from Twitter.</p>
<div id="attachment_1142" class="wp-caption aligncenter" style="width: 678px"><a href="http://ericfickes.com/wp-content/uploads/2010/03/tweetsproc_tweet-response1.png" rel="lightbox[1133]"><img class="size-full wp-image-1142" title="Twitter response from tweet sproc" src="http://ericfickes.com/wp-content/uploads/2010/03/tweetsproc_tweet-response1.png" alt="Twitter response from tweet sproc" width="668" height="719" /></a><p class="wp-caption-text">Tweetsproc returns the full Twitter response</p></div>
<p>That&#8217;s one sample CLR SPROC in the bank!  Feel free to download this code and try it out yourself.  I&#8217;d love to get some feedback on anybody looking to use this for real.  While tweeting from a stored procedure probably isn&#8217;t a hot topic for anybody, this is a nice teaser for what you can do with CLR sprocs now.</p>
<p><a title="CLR SPROC &gt; Tweetsproc sample code" href="http://ericfickes.com/code/tweetsproc.zip" target="_blank">Download code here.</a></p>
<p>Inside this zip you&#8217;ll find this.</p>
<ul>
<li>install.sql is everything you need to install this on your database</li>
<li>tweetsproc.dll is the twitter assembly used by the sproc</li>
<li>tweetsproc folder is the .net class library project</li>
</ul>
<div id="attachment_1139" class="wp-caption aligncenter" style="width: 289px"><a href="http://ericfickes.com/wp-content/uploads/2010/03/tweetsproczip.png" rel="lightbox[1133]"><img class="size-full wp-image-1139" title="Contents of tweetsproc.zip" src="http://ericfickes.com/wp-content/uploads/2010/03/tweetsproczip.png" alt="Contents of tweetsproc.zip" width="279" height="114" /></a><p class="wp-caption-text">Everything you need to get TWEETING from a sproc</p></div>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/03/how-to-tweet-from-a-sql-crl-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Find out why Visual Studio&#8217;s publish fails</title>
		<link>http://ericfickes.com/2009/08/find-out-why-visual-studios-publish-fails/</link>
		<comments>http://ericfickes.com/2009/08/find-out-why-visual-studios-publish-fails/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 18:51:26 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[build options]]></category>
		<category><![CDATA[msbuild]]></category>
		<category><![CDATA[output panel]]></category>
		<category><![CDATA[publish]]></category>
		<category><![CDATA[publish failed]]></category>
		<category><![CDATA[publish options]]></category>
		<category><![CDATA[verbosity]]></category>
		<category><![CDATA[visual studio 2008]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=876</guid>
		<description><![CDATA[Have you ever had Visual Studio tell you your web application publish failed, but never gives you a reason why?  You&#8217;re not alone.  I&#8217;ve been putting off looking into this issue on a project and just found a way to get my answer right away. Here&#8217;s what you should do inside of Visual Studio to [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever had Visual Studio tell you your web application publish failed, but never gives you a reason why?  You&#8217;re not alone.  I&#8217;ve been putting off looking into this issue on a project and just found a way to get my answer right away.</p>
<div id="attachment_877" class="wp-caption aligncenter" style="width: 276px"><a href="http://ericfickes.com/wp-content/uploads/2009/08/visual-studio-2008-publish-failed.gif" rel="lightbox[876]"><img class="size-full wp-image-877" title="visual-studio-2008-publish-failed" src="http://ericfickes.com/wp-content/uploads/2009/08/visual-studio-2008-publish-failed.gif" alt="Visual Studio 2008's Publish Failed message" width="266" height="112" /></a><p class="wp-caption-text">Visual Studio 2008&#39;s Publish Failed message</p></div>
<p>Here&#8217;s what you should do inside of Visual Studio to find out why your publish failed.</p>
<ol>
<li>Click the Tools menu &gt; then Options to bring up the Options dialog.</li>
<li>Expand &#8216;Projects and Solutions&#8217; on the left and click General</li>
<li>On General, click &#8216;Show Output window when build starts&#8217;</li>
<li>Now click on &#8216;Build and Run&#8217; in the left tree</li>
<li>Next select a value from the &#8216;MSBuild project build output verbosity&#8217; drop down menu</li>
<li>OK your way back to the main Visual Studio window</li>
<li>The next time you Build or Publish your project, you should see the Output panel pop up.  If your publish is still failing, the answer will live inside the Output panel</li>
</ol>
<p>Here&#8217;s a visual walkthrough of these instructions.</p>
<div id="attachment_878" class="wp-caption aligncenter" style="width: 310px"><a href="http://ericfickes.com/wp-content/uploads/2009/08/show-output-window-when-build-starts.gif" rel="lightbox[876]"><img class="size-medium wp-image-878" title="show-output-window-when-build-starts" src="http://ericfickes.com/wp-content/uploads/2009/08/show-output-window-when-build-starts-300x172.gif" alt="Tools &gt; Options &gt; Projects and Solutions &gt; General" width="300" height="172" /></a><p class="wp-caption-text">Tools &gt; Options &gt; Projects and Solutions &gt; General</p></div>
<div id="attachment_879" class="wp-caption aligncenter" style="width: 310px"><a href="http://ericfickes.com/wp-content/uploads/2009/08/msbuild-project-build-output-verbosity.gif" rel="lightbox[876]"><img class="size-medium wp-image-879" title="msbuild-project-build-output-verbosity" src="http://ericfickes.com/wp-content/uploads/2009/08/msbuild-project-build-output-verbosity-300x171.gif" alt="Tools &gt; Options &gt; Projects and Solutions &gt; Build and Run" width="300" height="171" /></a><p class="wp-caption-text">Tools &gt; Options &gt; Projects and Solutions &gt; Build and Run</p></div>
<div id="attachment_880" class="wp-caption aligncenter" style="width: 310px"><a href="http://ericfickes.com/wp-content/uploads/2009/08/visual-studio-output-panel.gif" rel="lightbox[876]"><img class="size-medium wp-image-880" title="visual-studio-output-panel" src="http://ericfickes.com/wp-content/uploads/2009/08/visual-studio-output-panel-300x102.gif" alt="Visual Studio's Output Panel" width="300" height="102" /></a><p class="wp-caption-text">Visual Studio&#39;s Output Panel</p></div>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2009/08/find-out-why-visual-studios-publish-fails/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Retrieve the current row of a DataBound List Control ( .net )</title>
		<link>http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/</link>
		<comments>http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/#comments</comments>
		<pubDate>Wed, 22 Feb 2006 20:00:00 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Current Row]]></category>
		<category><![CDATA[DataBound]]></category>
		<category><![CDATA[ListControl]]></category>

		<guid isPermaLink="false">http://ericfickes.com/2006/02/22/70/</guid>
		<description><![CDATA[This has taken too long to figure out. If you want to get the current row number of an item being DataBound to a List control ( DataGrid, Repeater, etc ), use this line of code in your aspx code : &#60;%# Container.ItemIndex+1 %&#62; And if you want to get the number of records in [...]]]></description>
			<content:encoded><![CDATA[<p>This has taken too long to figure out.  If you want to get the current row number of an item being DataBound to a List control ( DataGrid, Repeater, etc ), use this line of code in your aspx code :</p>
<p><span style="font-family: courier new; color: #000000;"><span style="color: #990000;"><span style="font-weight: bold;">&lt;%#</span> Container.ItemIndex+1 <span style="font-weight: bold;">%&gt;</span></span></span></p>
<p>And if you want to get the number of records in your DataBound control, do this</p>
<p><span style="font-family: courier new; color: #000000;"><span style="color: #990000;"><span style="font-weight: bold;">&lt;%#</span> YourControlId.Items.Count <span style="font-weight: bold;">%&gt;</span></span></span></p>
<p><span style="font-family: courier new;">Where YourControlId is the id of your DataBound control, such as an ASP:Repeater</span></p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2006/02/retrieve-the-current-row-of-a-databound-list-control-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
