Wednesday, 27 July 2011

No send action on Visio 2007 activity diagram signal shapes

One thing that’s not intuitive in Visio 2007 is how to change the text on a UML activity diagram signal element. When you first drag the signal shape on to an activity diagram it displays the text “<no send action>”.

Untitled3

 

No amount of editing properties will change that unless you do some thing like the following:

1. Create a new Static Structure Diagram (if you haven’t got one already).

2. Using the UML Static Structure shape palette drag a new Signal on to the Static Structure Diagram.

Untitled2

 

3. Right-click on the signal and open Properties.

4. Change the Name to whatever you want to signal to be called.

5. Return to your Activity Diagram and using the UML Activity Diagram palette add a Signal to your activity diagram.

6. Right-click on the signal and open Properties.

7. Choose Actions from the left-hand pane.

8. Select the Send Action and choose Properties.

9. Under Send Action you can now see the signal you added to the Static Structure diagram in the Signal drop down. Select it.

Untitled4

 

10. OK to all the dialogs and now the name of the signal appears on your signal shape.

Untitled5

 

Intuitive, isn’t it!

Monday, 25 July 2011

Renaming files with PowerShell

Problem: I had a directory full of PDF files that needed renaming. Specifically, I had to remove part of each file name.

Solution: Let’s try PowerShell!

PowerShell has been sitting on my machine for ages but for some reason I haven’t got around to using it. This seemed like a great opportunity to get my feet wet and – happily - this example turned out to be very straight forward. Firstly, I discovered that PowerShell was installed to C:\WINDOWS\system32\windowspowershell\v1.0 and I checked that the directory was in my Path system environment variable.

I launched Console2  - it’s so much more fun than using the standard Windows command prompt – and changed directory to the one holding the files I wanted to rename. I then ran powershell.exe which brought up the PowerShell command prompt and used the following PowerShell command to rename the files in the current directory:

get-childitem *.pdf | foreach{rename-item $_ $_.Name.Replace("text to replace", "")}

 

Untitled 

 

That was it. The files were renamed replacing “text to replace” with an empty string.

References

Wednesday, 22 June 2011

Bulk copy, full text and a severe error

I have a program that is using SqlBulkCopy to batch update data in a SQL Server Express 2008 database. Everything was working fine until, for no apparent reason, the bulk inserts failed with the following exception:

“A severe error occurred on the current command. The results, if any, should be discarded.”

After much hair pulling the cause of the error turned out to be the addition of a full text index on one of the fields being updated. Removing the full text index stopped the exception from being thrown. That’s all well and good but I needed a full text index.

The index had been defined something like this:

EXEC sp_fulltext_database 'enable'
GO

CREATE FULLTEXT CATALOG MyCatalog
GO

CREATE FULLTEXT INDEX ON dbo.MyTable
(
    MyColumn
    Language 0X0
)

KEY INDEX PK_MyTable ON MyCatalog WITH CHANGE_TRACKING AUTO

After some experimentation the problem seemed to be with the CHANGE_TRACKING option. By setting it to OFF the bulk copy worked fine but failed with either AUTO or MANUAL.* For my purposes this was acceptable because the data was fairly static and updated infrequently. I was left with having to ensure the index was rebuilt or populated appropriately as a separate process.

 

References

* Full-Text Index Population - http://msdn.microsoft.com/en-us/library/ms142575.aspx

Monday, 20 June 2011

Error installing SQL Server Express 2008

I ran in to an issue when trying to install SQL Server Express 2008 with Advanced Services. The installation file was a single executable (SQLEXPRADV_x86_ENU.exe)  but when I ran it I got the following error in a dialog box:

“SQL Server Setup has encountered the following error:

Invoke or BeginInvoke cannot be called on a control until the window handle has been created..”

The solution to the problem is:

  1. SQLEXPRADV_x86_ENU.exe is a self-extracting Zip file. Use WinZip to extract it to a local folder.
  2. Open a command window and navigate to the folder containing the extracted setup files.
  3. Run setup.exe from the command prompt.

That’s it.

Note that if you want to use Add or Remove Programs feature to add new features you can use the extracted files as the ‘installation media’.

Sunday, 12 June 2011

A few useful exception types

Sometimes it’s useful to throw exceptions from your code, for example if an incoming method argument is incorrect for some reason. Throwing Exception isn’t very specific so what should we throw and when? Here’s a quick aide-mémoire for a few exception types I use:

Exception type When to use it
ArgumentException The exception that is thrown when one of the arguments provided to a method is not valid.
InvalidOperationException The exception that is thrown when a method call is invalid for the object's current state.
FormatException The exception that is thrown when the format of an argument does not meet the parameter specifications of the invoked method.
NotImplementedException The exception that is thrown when a requested method or operation is not implemented.

References

http://msdn.microsoft.com/en-us/library/system.systemexception.aspx
Sunday, 12 June 2011,

Monday, 6 June 2011

Saving changes is not permitted

I’ve run into this problem a couple of times now and it’s really annoying every time it happens. I created a table in SQL Express using the SQL Management Studio and saved it. I then tried adding some new columns to the table but when I saved it again the following error appeared:

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.”

The dialog is really helpful:

Untitled

The solution is as follows:

  1. Go to Tools > Options…
  2. Select the Designers node.
  3. Uncheck the Prevent saving changes that require table re-creation option.

 

Untitled

Job done.

Wednesday, 25 May 2011

SQL revision - the GROUP BY clause

Every now and then I like to go back and have a look at something I think I know and double check my assumptions and understanding. In this case I’m going to look at the GROUP BY clause in SQL.

Partitions

Firstly, let’s look at partitions in sets. This is important because it directly relates to the ‘groups’ returned by a GROUP BY clause.

“A partition of a set X is a set of nonempty subsets of X such that every element x in X is in exactly one of these subsets.” *

We can derive certain properties of partitions:

  • The union of all the partitions (subsets) returns the original set
  • The intersection of the partitions (subsets) is empty

We can think of this like dividing a pizza into pieces. Each piece is a partition, and joining the partitions together gives us the original pizza.

image_thumb[3]

The ‘groups’ returned by a GROUP BY clause are effectively simple partitions of the original set of data.

The GROUP BY clause

When we use a GROUP BY clause we are taking the resulting set of data from a query (consisting of a FROM and WHERE clauses) and then put the rows into groups (partitions) based on the values of the columns specified in the GROUP BY clause.

Each group becomes a single row in the result table. Each column in the row must be a characteristic of the group not of a single row in the group. Therefore the SELECT list must be made up of grouping columns or optional aggregate functions. Note also that groups, by definition, must have at least one row (i.e. they can’t be empty). his means that the result of a COUNT will never return zero when used in a query against a non-empty table. Groups are also distinct.

The resulting table of a GROUP BY is called a group table. All subsequent operations are executed on the rows in the group table rather than the original rows.

NULL values are generally treated as a single group.

groupby

The columns in the SELECT statement can be a subset of the columns in the GROUP BY clause, but the columns in the GROUP BY clause can never be a subset of the columns in the SELECT statement.

References

* Partition of a set, Wikipedia

Wednesday, 25 May 2011