Archive for March, 2006
Override the rendering of the ASP.NET 2.0 controls.
In April, the ASP.NET team will ship examples on how to use ControlAdapters for the ASP.NET 2.0 controls. This is a really good idea, because very few people knows how to override the rendering of the standard ASP.NET 2.0 controls. The ControlAdapters allows the developers to render the controls in a really nice way instead of using tables, which seems to be the Microsoft way. For instance, the menu control can be rendered with <ul><li> tags and be customized with CSS classes. This is a really nice feature that few people know about.
Working with Visual Studio 2005 and ADO.NET
Seems like there are some changes in how to work with related tables in Visual Studio 2005 compared to VS 2003. I really like working with the designer tool as it does a lot of timeconsuming stuff for you. It's really easy to work with typed datasets by dragging and dropping the tables from theServer Explorer into the designer. But there are some hick ups that are really diffucult to find the answers to. In my opinion, Microsoft are really good in making Mickey Mouse examples and not real life examples. What happens when you for instance are trying to update two tables that are related at the same time ? Well, you get an SqlException, typical like:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Customers_Employees". The conflict occurred in database "EnterpriseCRM", table "dbo.Employees", column 'EmployeeId'.
The statement has been terminated.
yuck! Ths was really not the intention.
Here is the solution:

Figure 1: An Enterprise CRM system
My database schema looks something like figure 1 (added to the Visual Studio designer by dragging and dropping). I have added a couple of queries to the Customers table, but have nothing to do with the example.
Now, here is the code that generates this error:
Here is the code that does the logic. It's adding some new rows to the Customers and Employees tables, and setting the relations between the rows. The relation is the newCustomer.EmployeesRow = newEmployee:
ds = new DataSetEnterpriseCRM();
ds.GetRegions();
for (int i = 0; i < 3; i++)
{
DataSetEnterpriseCRM.EmployeesRow newEmployee = ds.Employees.NewEmployeesRow();
newEmployee.Name = "SomeOne";
DataSetEnterpriseCRM.CustomersRow newcustomer = ds.Customers.NewCustomersRow();
newcustomer.Region = 1;
newcustomer.Name = "New TestRelatedRow";
newcustomer.EmployeesRow = newEmployee;
newcustomer.KAM = newEmployee.EmployeeId;
ds.Employees.AddEmployeesRow(newEmployee);
ds.Customers.AddCustomersRow(newcustomer);
}
ds.SaveEmployeeAndCustomer(ds);
The code in the partial class of my DataSet. This code updates the tables in the database by calling the update method on the TableAdapters:
public void SaveEmployeeAndCustomer(DataSetEnterpriseCRM dataSet)
{
CustomersTableAdapter adapter = new CustomersTableAdapter();
EmployeesTableAdapter employeeAdapter = new EmployeesTableAdapter();
employeeAdapter.Update(dataSet.Employees);
adapter.Update(dataSet.Customers);
}
This code is perfectly legal and should teoritically work fine, but instead you will get the error message described above. Seems like there are some problems with cascading updates. There is, and here is the solution to the problem.
Configuring the relation
You need to configure the Typed DataSet. By default it does not support cascading updates. It is easy to do, but not well documented anywhere! One should maybe think that this was automatically supported when dragging and dropping the tables from the designer, but that's not the case.
Double-click the relation between the tables and you will get the following properties box:
Notice the dropdownlists
Set the update and delete dropdowns to "cascade" and the radiobutton to "Both Relation and Foreign Key Constraint".
Updating the AutoIncrementSeed and AutoIncrmentStep
This is only necessary if you are using AutoIncrement for the primary key. You need to specify that the increment seed should start with -1 and that the step should be -1. Click the table containing the primary key and select properties for the primary key column.

Set the AutoIncrementSeed and the AutoIncrementStep to -1 if you are using AutoIncrement for the primary keys.
This will cause the keys to be -1, -2, -3 and so on. This prevents the keys from interferring with the keys in the database. When the update methods of the adapters are executed, the keys will change and fetched again from the database. You can double check that by looking at the insert statement in the adapter. There is an select right after the insert which is returning the Identity_scope of the inserted row. That will always the latest incremented key inserted. The best of all is that the foreign key relation will be correct when the primary key is inserted before the row containing the foreign key.
Now, everything should be up to shape and the relations should work. Happy coding!
[Updated] Continuous Integration using an LCD-TV
You have probably seen examples of doing CI (Continuous Integration) using lamps. Shortly explained, the idea is that when the build breaks, the red lamp is turned on and when the build is OK, the green lamp is turned on. It's a pretty cool feature, so I thought of moving this idea a step further! Lamps are for dinosaurs
I have already implemented CI using the excellent example in Khushboo's blog. It's implemented with Team Foundation Server RC. The setup with the LCD-TV can be used in any CI environment, the idea is the same. Every time a developer checks in code, the build process is triggered. The display on the LCD-TV is just a custom website displaying the status of the build-server. The website has an auto-refresh (every 5th second or so) to get the latest status. When building, the screen turns yellow, and when the build fails, the screen turns red. The screen is green when everything is OK.
Here are some screens from our setup:
The OK screen:
The Build screen:
The Failed build screen:
The setup:
The setup is quite simple actually, you need the following items:
- A huge LCD-TV (at least 37" to make the people in the back happy)
- A laptop/PC/server to connect the LCD-TV. This will serve as a client.
- The FireFox browser (it supports blinking text
, IE don't) - A website that displays the result of the process. Should probably be installed on the build server.
and of course, you need a Project Leader that sees the point in investing a couple of bucks in a good development environment. It's not a simple task, but at least it's worth it. The quality of the code will definitively be better and the status of the build is very visible for the project team. My experience is that the red screen is not red for long, especially when your face is on it
Server setup:
- Install TFS Build Service on server
- Install VS 2005 Team Suite or VS 2005 Team Edition for Software Developers (code analysis/fxCop) + VS 2005 Team Edition for Testers (Code Coverage)on server
- Install VS 2005 Web Deployment Projects on server for deployment possibilities. Only needed for web projects, though.
- Create WebSite for CI (for instance http://[tfsserver]:8090). Use code in ci.zip (download further down on this page). Use the same AppPool as TFS (TFS AppPool)
- Configure web.config for CI
- Run the following command on server: “%programfiles%\Microsoft Visual Studio 2005 Team Foundation Server\TF Setup\BisSubscribe.exe /eventType CheckinEvent /address http://[tfsserver]:8090/service/WebService.asmx /deliveryType Soap /domain http://[tfsserver]:8080”
- Check in the following table in SQL server that the subscription is registered: tfsintegration.dbo.tbl_subscription
Possibilities
Ok, you really don't need a LCD-TV to show a red or green screen. But, it's the information that is important. You could for instance display burn down charts, code quality, test result etc. when the screen is green. And how about a blue screen (no, not a BSoD) when the standup meeting is supposed to start (to get the team members attention). There are a lot of possibilities with this setup.
(update) Install and setup
Well, people, here is the source code.
The Webapplicaiton includes the status screen as well as the CI example in Khushboo's blog (a little modified, but mostly the same). Install the webapplication as a new Web Site in IIS (with a different port) on the build server (in my environment, I am running the build and tfs services on the same server). The status screen is using the TFS API instead of the webservices, so all DLL's need to be installed on the server running the status screen application. It should be possible to use the webservcies as well, if this setup doesn't suite you.
A couple of things:
- Remember to trigger the checkin event described in Khushboo's blog. The WebServcie is included in the web application in the CI code package. it's located in the Service folder.
- Remember to set the correct Application pool for the web application. It should be the same pool as for the TFS web application (TFS AppPool or similar)
- Use FireFox as the browser on the client machine connected to the TV. If you remove the standard toolbars and hit F11 the status page will fill the whole screen, which is really nice. It also supports blinking text.
- Do anything you wan't with the code and use it as you like, I don't care, but I'm interested in any cool changes you do to it, maybe it could be an Open Source project in the future.
- Don't spam me with support issues. Please post them in this blog, maybe we can figure it out together.
Good luck!
Feel free to come with ideas and feedback of the setup.
Strongly naming the Microsoft Enterprise Library
I suppose you have tried the Enterprise Library from Microsoft. You probably also used it in a project that should be strongly named. Seems like the compiled DLL's in Eneterprise Library are not Strongly named! Well, the intention is that, as long as the source code is shipped with Enterprise Library, the DLL's are not Strongly named. You have to do it yourself. Fair enough, and the solution is described in Tom Hollander's blog:
http://blogs.msdn.com/tomholl/archive/2005/04/05/405764.aspx
If you still can't figure it out, here are the gory details:
http://blogs.msdn.com/tomholl/archive/2005/12/02/499529.aspx#502110
Team Foundation Server licensing model
I have used Team Foundation Server Beta 3 refresh and RC for a while. The product has many of the same functionalities as CruiseControl.NET and nUnit, except that you get a complete package of tools and templates integrated with Visual Studio. Ok, that's fine, I actually like tightly integrated tools (when they work as expected), but how about licensing?
Ok, for you guys that have installed TFS and uses Continuous Integration or doing manual/nightly builds with the integrated build system, you have probably configured testing and code analysis for the build. But then you get some server errors, right?
Typical errors are:
In order to perform Code Analysis on managed binaries, MSBuild needs to launch FxCop. MSBuild is unable to locate the FxCop binaries. Make sure Visual Studio Team Edition for Software Developers or Visual Studio Team Suite is installed and run MSBuild from within the "Visual Studio Command Prompt" or specify the path to FxCop by setting the FXCOPDIR environment variable."
The installation documentation does not state that you have to install FxCop or Visual Studio 2005 for Developers on the machine. Well, anyway, you decide to fix the issue and installs Visual Studio 2005 for Developers. The errors goes away!
Then you start exploring with WebTesting and Load Testing, which are cool features in Visual Studio 2005 for Testers. But, again, you get some new errors:
C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\TeamBuild\Microsoft.TeamFoundation.Build.targets : warning : TestTypes\{37e36796-fb51-4610-8d5c-e00ceaa68b9f} could not be loaded because the TIP could not be instantiated for the following reason(s): Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.LoadTestPackage, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
….
Hmmm…this seems odd, I can't do load testing on the build server. Again trying to solve this issue, I installs Visual Studio 2005 for Testers on the Build Server. But, how about licensing? Do I need a new license to run my tests ? Well, not really. The Microsoft® Visual Studio® 2005 Team System Licensing states the following:
"As part of the build process, Team Foundation Server may run quality tests and/or analysis on the precompiled or compiled code. These tests rely on functionality found within Team System client products, typically within the Team Edition for Software Developers or Team Edition for Software Testers products. These products may be installed on the build machine by licensed users of those products, as long as they are not directly used by any individuals who are not licensed for those products. Team Foundation Server will gather results of the build as well as any quality tests or analysis and deposit them in the Team Foundation Server data repository."
In my team, only 1 person has the complete Team Suite, as it's quite expensive. We get Visual Studio 2005 for Developers through our partner program with Microsoft (Gold partner). In real life this means, it's OK to install VS 2005 Team Suite (or for Testers) on the Build server as long as one Team member has the license. But, the other team members cannot log on to the server and use the Team Suite to configure the build process. The license is personal, meaning that the person who has the license, can install it anywhere and do whatever he/she want's with it.
Still wondering wheter TFS is worth the license, as you can achieve the same results with OpenSource software, but with not so integrated tools. I would say, that if you have a license with Team Suite, go ahead and configure the TFS environment, if not go OpenSource.
A couple of links:
http://forums.microsoft.com/MSDN/showpost.aspx?postid=276741&siteid=1
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=98242&SiteID=1
Search
Knut Hamang
Recent Posts
Recent Comments
- Lori on Html to Pdf in .NET
- Susan on Html to Pdf in .NET
- Susan on Html to Pdf in .NET
- Ananth on Html to Pdf in .NET
- Tim M on Passing an object to ObjectDataSource




