Posts

Since When

I found a URLEncode function for SQL Server on the Internet and promptly ported it down to my code base, however like some code I find on the Internet it wasn't very good, here is a suggestion for all of us posting code: include the test cases also -- sort of like Blog Unit testing. Anyways here is the problem simplfied in this example code: DECLARE @c char SET @c = 'é' SELECT CASE WHEN (@c LIKE '[a-z]') THEN 'Huh?' ELSE 'Better' END Know I know that é is not between a and z, however the output says it is. There is only 26 letters from a to z, at least that is what I am teaching my three year old daughter. So what gives, must be a SQL server bug right? Whoops. Checking the documentation for LIKE it appears that I was being a little small minded -- since only my native alphabeta has 26 letters between a-z, there are some alphabetas that have a few extra letters and my SQL server configuration is taking them into consideration. So what do I have...

Disappointment Over Indexed Views

I upgraded to SQL Server 2005 Enterprise Edition today in order to use indexed views to implement better performance for my web site. Basically to short cut the multiple joins it requires to denormalize my web site data into something interesting. After upgrading, I was disappointed to learn that I couldn't use indexed views to help my performance. Indexed views are severly limited you can't have any outer joins, use other views, or do unions. So for my data, and almost any highly normalized data that you want join together to make it appear more denormalized you can't use indexed views. By indexed views I mean clustered unique indexed views that you can only get in enterprise edition SQL server. These views rewrite the data into a cluster and update when the underlying table updates. As long as the table doesn't bind to another with an outer join, or you want to stack views together you can achieve some performance gains. Just for a minute, after laboring 2-3 h...

Positive Integer In Transact-SQL

While the IsNumeric Function in Transact-SQL is good for finding out if a varachar is a integer or a deciaml. Sometimes it is nice to find out if the varchar is a positive integer here is how: CREATE TABLE #Temp (Number varchar(25)) INSERT INTO #Temp (Number) VALUES ('2.4') INSERT INTO #Temp (Number) VALUES ('4') INSERT INTO #Temp (Number) VALUES ('-4') INSERT INTO #Temp (Number) VALUES ('-4a') INSERT INTO #Temp (Number) VALUES ('4-a') INSERT INTO #Temp (Number) VALUES ('4-') INSERT INTO #Temp (Number) VALUES ('4444') SELECT * FROM #Temp WHERE ISNUMERIC(Number) = 1 AND NOT Number LIKE ('%.%') AND NOT Number LIKE '%-%' DROP TABLE #Temp With test cases. Modify it to find integers both positive and negative: CREATE TABLE #Temp (Number varchar(25)) INSERT INTO #Temp (Number) VALUES ('2.4') INSERT INTO #Temp (Number) VALUES ('4') INSERT INTO #Temp (Number) VALUES ('-4') INSERT INTO #Tem...

Adding To CheckBoxList

I always seem to be subclassing the standard .NET web controls and adding my own little features. Here is an enhancement that I made to CheckBoxList: public String[] SelectedValues { get { List<String> output = new List<String>(); foreach (ListItem listItem in Items) if (listItem.Selected) output.Add(listItem.Value); return (output.ToArray()); } } Now that I have this method I can convert the CheckBoxList to a CSV like this: String csv = String.Join( "," , checkBoxList1.SelectedValues); {6230289B-5BEE-409e-932A-2F01FA407A92}

Delete Command Twice in GridView

Image
The delete command is being called twice for each click on delete. What do I mean by this? With this code: <asp:GridView runat= "server" DeleteMethod= "DeleteRowById" ...> <asp:CommandField ShowDeleteButton= "True" /> </asp:GridView> I am getting the DeleteRowById method called which when the delete button in the CommandField is clicked. Doing some Internet research I found this: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105123 However, the workaround isn't right, basically all you need to do is change the <asp:CommandField to: <asp:TemplateField> <ItemTemplate> <asp:ImageButton runat=server id= "ImageButton1" CommandName= "Delete" ImageUrl= "..." CommandArgument='<%# DataBinder.Eval(Container, "RowIndex" ) %>' /> </ItemTemplate> </asp:TemplateField> You don't need to add a code behind...

Shutting Down a Running COM+ Instance

Image
If you have an instance of object running under COM+ (in the dllhost.exe process space) and you want to shut it down from C#, you can use the code below.  Note that ShutdownApplication only intializes the shutdown of the COM+ applicance, it will return sometimes before the application is finished shuting down.  So you need to check to make sure the applicatio is shut down before continue.  I use this code in my unit testing to kill the instance-- making sure that it is stateless.  Also note that you need to send the package id for the application -- this is the guid you used when installing the application into COM+.  It can be found on the first property page of the application properties in component manager. internal static void ShutDown() { Int32 count = 0; COMAdmin.COMAdminCatalog objAdmin = new COMAdmin.COMAdminCatalog(); // WWB: ShutDown The Application (All Instances) Using teh Package Id objAdmin.ShutdownApplication(Configuration...

Mesh and IE Favorates

Image
I have been playing around with Mesh a bit of late. Mostly good other than on a few of my machines, Mesh refused to install. Either the install itself failed or it just never allowed me to sign in. But, I figured out one use for Mesh this morning that made it all come together: sharing IE Favorites. After installing Mesh, share the following folder on each machine: Xp, 2003: C:\Documents and Settings\%USERNAME%\Favorites\Links Vista, 2008: C:\Users\%USERNAME%\Favorites\Links Make sure when resolving the share location of the folder on subsiquent machines, you browse to the location above. Now your IE links are synced across machines.