Thursday, May 3, 2012

Selecting the First Field in a Form

On an HTML page where you want the first field on the page to be selected by default, you can add the following code.  This uses jQuery to find all of the ‘text’ input boxes, and then sets the focus to the first one found.
<script type="text/javascript">
$(function (){
    $("input[type=text]").first().focus();
});
</script>

Or put this at the bottom of your master page if you want it done everywhere.

Thursday, September 29, 2011

Analysis Services - A duplicate attribute key has been found when processing

 

When you get a warning like the following when processing an Analysis Services Cube, it will usually be related to other errors in Processing. 

image

This has something to do with trimming in char columns.  To fix the problem, go into the properties of the offending column, and change Trimming to None:

image

Tuesday, August 9, 2011

Add Controller Menu Missing From VS2010 Context Menu

Normally in VS2010, when you right-click on the ‘Controllers’ folder, you will get a menu that includes 'Add/Controller’.  If this menu option is gone, it is because the project type is not setup correctly. 

To fix this:

  • Create a new blank MVC project.  Save and close the project.
  • Open up the csproj file in Notepad.
  • Copy the <ProjectTypeGuids> attribute.
  • Open up the csproj file you want to fix. 
  • Replace the <ProjectTypeGuids> attribute with the one you copied from the other file.

Friday, July 15, 2011

Querying an XML Column in SQL Server

User the ‘Value’ method on a column in t-sql to query the values of an XML column. So for example, if you have XML that looks like this:

   1: <EventDetails>
   2:   <EventSource>CAST</EventSource>
   3:   <EventType>CastSubjectAreaPublished</EventType>
   4:   <EventTimestamp>2008-12-16T00:42:34</EventTimestamp>
   5:   <EventArguments>
   6:     <SubjectAreaId>1000</SubjectAreaId>
   7:     <ClientId>3450</ClientId>
   8:     <UserId>3</UserId>
   9:     <WorkEventId>6515</WorkEventId>
  10:   </EventArguments>
  11: </EventDetails>

You can query it with T-SQL that looks like this:


   1: select top 20  
   2:     messagebody.value('(/EventDetails/EventType)[1]', 'varchar(50)') as EventType,
   3:      ( select max(SubjectAreaName) from EnterpriseODB..SubjectArea where
   4:         SubjectAreaId = messagebody.value('(/EventDetails/EventArguments/SubjectAreaId)[1]', 'int')) as SubjectArea
   5:     from processedmessagelog 
   6:     where messagebody.value('(/EventDetails/EventArguments/ClientId)[1]', 'varchar(10)') = 3450


Note that the ‘[1]’ tells sql to retrieve the first instance of that value.

Friday, June 17, 2011

Concatenating strings from multiple records into a single value

Say that you want to concatenate values from several records into a single string.  The classic example is a list of categories where you want to present it to the user as Category Name followed by a comma separated list of all products for that category.

There are multiple solutions for this problem, but this one seems to be the most straight forward:

   1: Select C.Name, 
   2:     stuff((select ', ' + P.Name 
   3:             from Product as P
   4:                 where P.CategoryId = C.Id
   5:             for xml path('')),1,2,'') as ProductList
   6:     from Category as C

Monday, June 13, 2011

Trouble Connecting to a Server on a Different Domain

Occasionally, when attempting to connect to a server on a different domain, you may get an error that says the credentials are incorrect even though you didn’t enter any credentials, or if you do enter the credentials, it says that these credentials conflict with an existing set of credentials.   To fix this, open a command prompt and enter the following command:

   1: net use \\server /delete

Then you should be able to connect to the server, either through the command prompt or through the command prompt:



   1: net use x: \\server\share /user:username password

Wednesday, March 23, 2011

UUID Already Exists Error When Registering a Virtual Hard Disk

When registering a hard disk with Oracle Virtual Box, if you get an error like the following:

image

It means you need to change the UUID of the disk.  This generally happens if you have cloned a disk.  To correct this, you need to run the VBoxManage program which comes with Virtual Box.  This is generally located in the C:\Program Files\Oracle\VirtualBox directory.   Open up a command prompt in this directory and do the following (filling in the name of your hard disk file where applicable:

VBoxManage internalcommands sethduuid c:\directory\MyHDFile.vhd