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

Tuesday, March 22, 2011

Invalid Target Namespace When Deploying a Report to SQLServer 2008

If you get an error like the following when deploying a report to SQLServer ReportingServices 2008, it is usually because the report was created in a design environment setup for SQL Server 2008 R2, but your server is SQL Server 2008 R1 (I know, that’s not what it’s called, but you know what I mean).

The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition' which cannot be upgraded. (rsInvalidReportDefinition)

To fix this error:

  • Edit the report RDL (Code View as it is called in BIDS).
  • Replace the Report header with the following:
    <Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" 
    xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">


  • Remove the <ReportSections> and <ReportSection> tags from the report. Note, remove the tags only.  Leave all content inside the tag.  Don’t forget to remove the closing tags for each of these.
  • Save the report.  You should now be able to upload it.

Thursday, February 24, 2011

Windows 7 and Program Files

With Windows 7, if you think you are putting something in the Program Files directory, you may actually be storing the file somewhere else.   Windows virtualizes this directory so that the files are stored in another location.

For example, if you drop an Access database into this location, and the Access database is updated, the updated copy will be stored in c:\Users\UserName\AppData\Local\VirtualStore\ProgramFiles.  All future references to this file will be virtualized to this location.  If multiple users are on the machine, they will each have their own copy of this directory, and a ‘Shared’ Access database will no longer be shared.

Wednesday, February 23, 2011

401.2 Error on IIS7

I was getting a 401.2 error on a website that I had moved to IIS7.  The website required Windows Authentication.  To resolve the issue:

  • Make sure the website users have access to the underlying files.
  • In the Application setup in the IIS console
    • Go to Basic Settings for the Application (in the right pane), and click on ‘Connect As …’.  Selection ‘Application User’.
      image
    • Click the Authentication icon in the IIS section.
    • Verify that ASP.NET Impersonation and Windows Authentication are both enabled. 
      image

Friday, February 11, 2011

Alternating Background Colors in a Tablix Group

When alternating background colors in a group in a tablix, you cannot use the traditional formula for alternating rows (which would be something like: =iif(RowNumber(Nothing) Mod 2, "White", "#E5E5E5")  )

Instead you must use the following:

  1. To go the Code for the report (found in the Report Properties dialog)
  2. Add an even number function, and an internal variable to track the current row:
     Public _evenRow As Boolean  
    Public Function EvenRow() As Boolean
    _evenRow = Not _evenRow
    return _evenRow
    End Function

  3. Go to the “Group Properties” for the Row Group that you want to alternate, go to variables, and add a variable called EvenRow. The expression for this variable should be =Code.EvenRow().  This will be executed each time the group is created.
  4. Finally, in the background property for the group row, you can enter a modified version of the original expression: =IIF(Variables!EvenRow.Value=true,”Red”,”Green”)

Tuesday, January 25, 2011

Fixing a Broken Event Broker Queue

When a database is restored from a backup, a lot of times the Service Broker is disable. Therefore any actions scheduled by the Event Broker will not happen.

To check if an Event broker is enabled:

 SELECT is_broker_enabled, [name], database_id FROM sys.databases WHERE database_id = db_id()  

To reenable the broker:

 ALTER DATABASE NameOfTheDatabase SET ENABLE_BROKER 

Saturday, January 15, 2011

Retrieving Identities on Bulk Inserts

If you need to insert a bunch of records at one time, and need to get the identity of all the inserted records, you can use a cursor.  But sometimes, using a cursor just feels wrong.  The “Inserted” key word comes to the rescue!  Use it like the following.  In SQL2008 they have further improved this so that you don’t even need the temp table.

     CREATE TABLE #newNotes (ID INT)  
INSERT INTO Note (NoteText)
OUTPUT INSERTED.NoteId INTO #newNotes
SELECT Note.NoteText
FROM Note
WHERE initial_report_number = @initialReportNum
INSERT INTO ClaimNote (claim_number, NoteId)
SELECT @claimNum, #newNotes.ID
FROM #newNotes
DROP TABLE #newNotes