Monday, December 18, 2006

Limitation of foreign-key constraints in SQL Server 2005

I encountered a limitation to how you can set the on-delete and on-update constraints for foreign-keys in SQL Server 2005. I have a table with 5 foreign-keys, all targeting the same column. I wished to have on-delete and on-update "Cascade" for all of them, this however was not permitted. Only one of them could have the cascade property set, the others I left with "No action" :(.

Units tests as an afterthought

This has probably been said elsewhere and I might even have read it there ;) Still I think it is worth mentioning here.

Ideally unit tests should written as a part of a test driven design (TDD), in this case they check for code's correctness. However, sometimes the unit tests don't get done instead the code is made bug-free by testing it by hand. In this case it is still of value to write unit tests, however the focus changes: The unit tests should guard the code against external changes that affect it, i.e. ensuring its pre-conditions. These unit tests test things such as:
  • DB schema changes: E.g. the code should still be able to load its configuration from the database.
  • Interfaces to external code: Just the simplest run through the code where all external interfaces are called should trigger test failure. This is not such an issue for strongly types languages, except where reflection is used.

Linking files between projects in VS2003

I think that linking existing files between projects should be made clearer in VS2003, not clicking on the obscure arrow next to the Open button.













I need to check if this has changed in VS2005.

Thursday, December 14, 2006

Secrets distract

Another interesting post at Chris Sells spoutlet was about the flow of information within companies. I think he is quite right in saying that secrets should not be withheld from employees.

Data will outlive programs

I got a small epiphany when reading an old entry by Chris Sells. It made me realize that the data in the database should be left as accessible as possible for future programs. The data will most likely outlive the program created to access it.

P.s.
Actually, the reason I ended up at Chris was because he had made available a nice tool to test regular expressions.

Thursday, March 02, 2006

SqlServer: indexes

Some points to remember about indexes in SqlServer 2000:
  • Primary key is a clustered unique index, but can be changed to non-clustered.
  • Clustered index: Data is physically sorted by the index. Important to keep the most selective column first in the index definition. Only one clustered index possible per table. If there is only one index on a table it should be clustered. Preferably the indexed column should contain a monotonically increasing value.
  • Non-clustered index: Symbolic links. Useful for single row look-ups. Can be up to 250 non-clustered indexes on a given table.
  • Select indexes based on perceived use of the table: what selects will be performed, what updates will be performed, etc.

Wednesday, March 01, 2006

Missing information on Remoting

I am missing a more detailed documentation on Remoting. Not for the lack of trying: I read the Msdn documentation and we own Ingo Rammer's "Advanced .NET Remoting". Specifically I would like to know the socket options used by the TCP channel and if the size of the Remoting ThreadPool can be easily changed, per application.

Are WeakReferences used in Remoting?

Thursday, February 23, 2006

System.Console in .NET 2.0

I like to use the Console to do small test applications and it bothered me how limited it is. E.g., I have not been able to control where to place the text in the console window. In .NET 2.0 the Console class has now been much updated, e.g., there is the great new function SetCursorPosition() :)

Another missing functionality in the Console 1.0 class is a non-blocking Peak(). This is useful as a condition in a while-loop (instead of spawning a second thread that blocks on Peak() or Read()). In version 2.0 there is now the KeyAvailable property that (supposedly) serves this purpose.

This is just to mention two of the many additions to the Control class.

Tuesday, February 21, 2006

Categorization of tests

I thought the following categorization of tests sufficient and complete:

"I believe that the traditional testing terms; unit tests, integration tests and system tests have become outdated. Instead I prefer the terms developer tests, functional tests and non-functional tests. Non-functional tests are things like performance testing, functional tests are tests that the customer cares about like use case tests or business transaction tests, and developer tests are everything else that the developer needs to test to prove to herself that the code is correct."
- Agile Development Checklist

Monday, February 06, 2006

C# 3.0

I read (skimmed through) Don Box's and Anders Hejlsberg's article on LINQ, also watched a short demonstration on DLINQ to become acquainted with next version of C#. One thing struck me and that is that Microsoft has been advocating the use of stored procedures rather than inline queries, but the DLINQ presentation was all about how to write compile-time-checked inline queries.
Hmmm...

Friday, January 20, 2006

Article on agile development

I read an article on agile development by Martin Fowler. I thought it was an excellent read. Just to get you excited I have extracted some of the points I found most interesting.

Traditional engineering and software development differ in a significant way. E.g., in building a bridge the design is about 10% of the effort, but in software development it is about 50% of the effort. This changes the nature of the work since design is a much more unpredictable process, requiring gifted (non replaceable) individuals, but construction is rather automated and less demanding on particular skills. Additionally, the requirements for software projects are more liquid making the software design process even harder to predict.

Since the individual developer plays such a big role in a software development the agile processes are focuses on how to mange them and their interactions, as opposed to the traditional approach based on the assumption that the individuals are replaceable parts. Finding a good measure of progress for these processes is difficult, and Martin quotes Robert Austin's conclusion that measurement-based management has to be abandoned for delegatory management.

The unpredictability of software development makes it hard to fix a budged up-front: it is impossible to fix time, price and scope. However, using agile methods, it is possible to allow the scope to vary while keeping the price and time fixed. The success of the project should therefore be measured by how much business-value it provides to the customer, rather than how well it meets its plan.

Martin concludes his article by describing some of the numerous agile methods in existence, this I found of less interest.

Thursday, January 19, 2006

Using database transactions in unit tests

I started using the advice of Roy Osherove regarding how to use transactions in unit tests (see previous blog entry).

To summarize the method:

using System.EnterpriseServices;

ServiceConfig config = new ServiceConfig();
config.Transaction= TransactionOption.RequiresNew;
ServiceDomain.Enter(config);

[database CRUD code]

if(ContextUtil.IsInTransaction)
{
ContextUtil.SetAbort();
}
ServiceDomain.Leave();

This code worked fine after having sorted out some configuration problems. I am accessing the SQL Server 2000 on a Windows 2003 server from a Windows XP on a different domain. First I got "The partner transaction manager has disabled its support for remote/network transactions.", this changed when I allowed for MSDTC on the server. Then I got "The transaction manager has disabled its support for remote/network transactions" which was fixed by allowing MSDTC on the client machine. The final error was because the firewall was blocking the connection.

Therefore in order to make this work (for this scenario) it is necessary to:
  • Allow MSDCT on the client and server: Administration tools -> Component Services -> Computers, right-click on My Computer, click on the "MSDTC" tab, click on "Security Configuration" and allow everything :) In particular: "Allow Outbound" on client, "Allow Inbound" on server (the SQL Server machine), set "No Authentication Required" on both server and client, and enable TIP and XA Transactions on both server and client.
  • In the firewall open up for the msdtc.exe: %root%\WINDOWS\system32\msdtc.exe on both client and server.

Now I am able to control the initial conditions of the database programmatically in a simple manner :)

P.s. The above settings work for me, but further instructions can be had here and here.

Wednesday, January 18, 2006

Interesting figures

On Tomshardware there is a interesting short comparison on present and past computer capabilities.