Geeks With Blogs
Bob Palmer's Developer Blog .NET, SQL, and Silverlight Development August 2009 Entries
Adventures in SVN
For my personal projects (and likely our work projects) I've been looking into Subversion as an alternative for VSS. And so far, I've only 'blowed up' my repository a dozen times in the installation process. I am by absolutely no stretch of the imagination an SVN expert (I just started tinkering with it this week), but figured I would toss out a few of the hurdles I toughed through in getting it up and running. After installing the product I got to spend a few frustrating days connecting to my server ......

Posted On Saturday, August 29, 2009 7:26 AM

C# Snippets: Conversions between Enum, Integer, and String
Here's a quick snippet on converting from an enum to Strings and Integers, and back again: Assuming the following enum: public enum Animals { dog=1, cat=2, bird=3 } enum to int To convert an enum to an integer, simply cast the integer as the enum type: Animals myAnimal =; int myAnimalInt = (int)myAnimal; int to enum This works in the same way (via a cast); int myAnimalInt = 1; Animals myAnimal = (Animals)nyAnimalInt; string to enum Using Enum.Parse, we can convert a string to an enum. ......

Posted On Monday, August 24, 2009 10:54 AM

SQL 2K5: Quickly Backup/Restore all user databases
I decided to poke my head out of the bottomless cave that is Facebook/Silverlight development to post a nifty script we use at my current job to quickly back up all of our user databases after our production migrations, and copy these over to a handy network share: CREATE PROCEDURE sp_BackupAllData AS DECLARE @dbName VARCHAR(50) DECLARE @bakName VARCHAR(100) DECLARE db_cursor CURSOR FOR --Skip the System databases SELECT name FROM sysdatabases WHERE dbid > 4 OPEN db_cursor FETCH NEXT FROM db_cursor ......

Posted On Thursday, August 20, 2009 8:21 AM

Update: Accessing embedded files via Reflection
In my previous post, I was working with SMTP, HTML mail templates, and String.Format to easily create HTML emails with dynamic content. We're now going to crank up the awesome a bit, and use reflection and embedded files to make this even better. The first part is easy. To embed a file into your assembly, simply go to the object's properties, and change the Build Action to Embedded Resource. We can now access this resource programatically with the following code snippet: public Stream GetEmbeddedFile(string ......

Posted On Friday, August 14, 2009 8:16 AM

HTML Emails with Dynamic Content made easy!
As a part of our main customer-facing site, we send out a ton of e-mails - daily status reports, invoices, etc. and we needed a simple mechanism to allow for easy editing of our HTML emails, while allowing them to have dynamic parameters (i.e. fields from a datatable, etc.) We start by creating a separate HTML file with all of our formatting, and parameter placeholders for our dynamic data (i.e. "Hello, {0}"). The code snippet itself is pasted below: //Set up our SMTP client SmtpClient scli = new ......

Posted On Thursday, August 13, 2009 3:10 PM

Handling contention in SQL2K5
At my current organization we run a huge number of batch processes, and many of these have to go through a rules engine. Essentially, the rules engine grabs all of the stuff that needs to be processed, and informs other processes that it's working with that set of data. The problem we needed to solve was how do you ensure only one instance of the rules engine grabs a specific record or set of records without explicit locking. Or, in the words of one of my developers, if two people reach for the same ......

Posted On Wednesday, August 12, 2009 11:10 AM

Array Parameters in SQL2K5
A fairly common task in working with components and their associated SQL procedures is the need to work with an array of data. As we know, arrays are not natively supported in SQL2K/2K5. Here's a quick way to build a flexible and reusable function to handle this. CREATE FUNCTION [dbo].[fn_ArrayTable] (@ArrayData VARCHAR(MAX), @Delimiter NCHAR(1)) RETURNS @Table TABLE ( idx INT IDENTITY(0,1), Data VARCHAR(255) ) AS BEGIN DECLARE @EndIndex INT DECLARE @StartIndex INT DECLARE @CurVal VARCHAR(255) SET ......

Posted On Tuesday, August 11, 2009 1:52 PM

Determining HTTP or HTTPS in ASP.Net
At the company where I work, we sometimes have to dynamically build URLs - for example, when a user requests a medical claim PDF, these are generated on the fly and a webservice returns a URL to navigate to. In our production systems, these are always HTTPS - but in Development, these may be HTTP if an SSL cert is not present. To work around this, we can dynamically determine if the current page is secure, and adjust our dynamically generated link accordingly, as illustrated below: string pdfUrl= ......

Posted On Tuesday, August 11, 2009 11:36 AM

Copyright © BobPalmer | Powered by: