Posts

What A Week!!!!

I just returned from BUILD 2012 and I can’t say enough about it. If you’ve never been to a Build or PDC, you haven’t been to a conference. Microsoft pulls out all the stops!!! It is amazing. Of course, the goodies are great but they pale in comparison to the people you meet and what you learn. The People I met some amazing folks but my Hackathon team is at the top of the list: Glenn Henriksen , Geir-Tore Lindsve , Laura Thompson and Joseph Tu . Five folks who had never met came together win the Windows Azure category! These folks rock! I also met some ‘softies who just plain kick tail! Sreekanth Kannepalli was our mentor for the Hackathon and was invaluable in our win. We also got help from Denis Delimarschi. Of course, I can’t forget the Dan Fernandez, the host and moderator. It rocked, Dan!!! Arif Shafique and Theo Yaung are two other folks I met through the days. I’m telling you, Microsoft has some smart cookies!! The Goodies Each attendee got a Microsoft Surface RT 32GB, a N...

Diffference Between RegEx.IsMatch and the RegularExpressionAttribute

I was working on some code that stores a month as CCYYMM string. Of course I wanted to validate the string with Regex so I had the pattern ^20[0-2][0-9](0[1-9])|(1[0-2])$ Everything was fine as long as I was using Regex.IsMatch. The problems started when I used the RegularExpressionAttribute. Suddenly, I was getting errors everywhere. I constructed a little test to verify that there was a difference. What I found was that using the same string and pattern, yielded different results. Here’s my unit test. [TestMethod] public void DifferenceBetweenIsMatchAndRegExAttribute() { var pattern = "^20[0-2][0-9](0[1-9])|(1[0-2])$"; int cnt = 0; var months = new string[] { "201001", "201002", "201003", "201004", "201005", "201006", "201007", "201008", "201009", "201010", "201011", "201012" }; var attribute = new RegularExpress...

Updated Code To Get Class Definition From Table Structure

My previous post on Script to Create MetadataType classes was to work with LINQ-To-SQL and partial classes. EF 4.1 introduces Code First which uses POCOs and here is the code to create a class definition from a table’s structure. Enjoy. SET NOCOUNT ON declare @TableName varchar(256) = 'BusinessTypes' declare @EntityName varchar(256) = 'BusinessType' declare @TableSchema varchar(256) = 'dbo' declare @ColumnName varchar(256) , @DataType varchar(256) , @NewDataType varchar(256) , @MaxLength int , @Nullable varchar(5) declare @Lines table (Line varchar(1000)) insert into @Lines select 'public class ' + @EntityName insert into @Lines select '{' declare @DataTypes table (SqlDataType varchar(1000), DataType varchar(1000)) insert into @DataTypes (SqlDataType, DataType) values ('bit', 'bool') insert into @DataTypes (SqlDataType, DataType) values ('char', 'string') insert into @DataTypes (SqlDat...

Replacement for ExpectedException in MS Test

This StackOverflow thread has a great solution for the issue that ExpectedException does not allow you to validate the error message. Look at the response from winSharp93 and the ExceptionAssert class. This is a much cleaner method and also shows some great ways to use generics.

Script To Grab Column Names As UML Properties

I was cooking up some UML diagrams for an existing DB and wanted to get all of the properties. It lists the table, column name in UML markup format and then the data type. The data type column is there so that all I have to do is order it by the second column and I’ll get all of the nulls so I can see if I’m getting a data type that I haven’t handled. The data type conversion is by no means complete but it’s a good start. Enjoy! select table_name, '+ ' + column_name + ' : ' + CASE WHEN DATA_TYPE in ('ntext', 'nvarchar', 'varchar', 'char') then 'string' WHEN DATA_TYPE = 'bit' then 'bool' WHEN DATA_TYPE = 'int' then 'int' WHEN DATA_TYPE = 'timestamp' then 'timestamp' WHEN DATA_TYPE = 'uniqueidentifier' then 'Guid' WHEN DATA_TYPE = 'money' then 'decimal' WHEN DATA_TYPE in ('smalldatetime', 'd...

SQL To Find String In Procedure/Function

I do a lot of work updating legacy systems. Almost every system needs the column names updated since the names are usually short and not very descriptive. Here’s a command for finding all store procedures/functions that use a specified column. select s.name, a.name FROM sys.sql_modules m inner join sys.all_objects a on m.object_id = a.object_id inner join sys.schemas s on a.schema_id = s.schema_id where m.definition like '%MyColumnName%' INFORMATION_SCHEMA.ROUTINES is unreliable because it is limited to the first 4000 characters. Enjoy!!

Read XML File Into SQL Server

Wayne Sheffield has a nice article on reading XML files into sql. You can find it here.