Pushing Pixels

Computing and Digital Imaging

Pushing Pixels random header image

Determining row counts for all tables in a database

January 11th, 2007 · ASP2, SQL

Here is a usful snippet if you want a way to get the number of rows in each table in your database. I use this in an admin-only page of the web application to provide some at-a-glance statistics. It is also really useful in unit tests for checking the correctness of business logic that may create new entries in several tables in one transaction.

[Read more →]

→ No CommentsTags:

Formatting code in Wordpress

January 11th, 2007 · Blogging

What a pain in the rear! Wordpress appears nice as a blogging tool, but my attempts to format some code snippets was painful beyond belief.

Every time I pasted some code in and surrounded it with the code tags, the generated HTML had extra paragraph markers and line breaks, and screwed up the position of the closing code marker.

Even a search for plugins did not cure things. I installed one or two “code formatting” plugins that made things a little better, but still required a lot of post-paste editing of code to get anything like presentable.

It turns out that the Rich Text Editor in Wordpress 2 is to blame - it completely messes up. So my advice is to disable this from your user profile.

The thing that rankles is that the rich editor is enabled by default. I did not even know it was optional until I did a Google on code formatting in Wordpress. It all just seemed much much harder than it should.

Anyway, hopefully this snippet will save others the problem in the future.

→ No CommentsTags:

Useful CSV reader

January 10th, 2007 · .net, Software Development

To aid my unit testing I needed to populate a database with a load of test data. This data needs to be generated by some of the less technical guys on the project and so exporting CSV (Comma Separated Values) files from Excel seemed a sensible approach. So I then cast around for any existing code that would save me having to write a robust CSV parser. The search turned up this on CodeProject:

LumenWorks.Framework 

The neat thing about it is that you can get field values either by index position or column name, assuming you put column headers in your file. The column name feature really helps out with maintainance of the test data as we evolve and vary the schema slightly - we can insert columns with no worries about upsetting existing reader code.
It’s easy to use and install in your own project, and the CodeProject article describes the basic usage pattern. At the moment it is just linked in to the unit test framework, but is so useful I will probably make it a part of the core application libary to facilitate importing data from customers as we anticipate some of our customers could have thousands of records to import when they move to our system.

→ No CommentsTags:

Don’t believe NUnit!

January 5th, 2007 · ASP2

Just a quick note about a little problem I found using Nunit (2.2.9, but affects earlier revisions too).

After a bunch of edits to my project, I suddenly started getting messages from NUnit GUI “could not load file or assembly nunit.core”. Try as I could, this would not go away. This included everything from reinstalling NUnit to tracking DLL loading via SysInternal’s Process Explorer tool.
My project is non trivial - a top level solution containing an ASP2 web project, a couple of library DLL’s for the business logic, a unit test exe, and a testing helper library to help cross reference test results against direct SQL calls. As I’ll be writing about in another post shortly, incorporating unit testing into an ASP project is a pain in the rear and so I had been restructuring things. My natural assumption based on the error message was I had messed up something in the linking/referencing.

But it turned out to be an error in the application config file - for some reason NUnit reports this as a DLL missing, not that you have mistyped a bit of config text. I simply had a closing tag in the wrong place - still syntactically correct, however.
This link is by someone else who hit the exact same problem, and he has written about in more detail.

So remember folks: never assume a programmer - even those as good as the NUnit guys - generate the correct error message for all circumstances.

→ No CommentsTags:

Perforce server logging problem

January 2nd, 2007 · Perforce, Software Development

When setting up a server it is often useful to enable one of the logging levels. The admin guide states that you need to do this:

  • p4 set P4DEBUG=server=2


which sets the server logging level to 2. You then need to restart the Perforce server.

However, if Perforce is running as a service (the default under Windows), then this does not work. The reason is that “p4 set” only sets the variable in for HKEY_CURRENT_USER in the Windows registry. However, when running as a service, p4d picks up its environment variables from HKEY_LOCAL_MACHINE. To do this you need to set the ‘-s’ flag. E.g.

  • p4 set -s P4DEBUG=server=2

→ No CommentsTags:

Adding ASP Role tables to your own database

December 29th, 2006 · ASP2

This is still work in progress, but I want to incorporate the user role management tables within my own database, as the concept of users and their distinct roles ties right in with the core business model of the new site.
The following link explains the standalone tool to create the tables:
ASP.NET SQL Server Registration Tool

Invoking the exe runs a wizard requesting the database service - it needs to match the connection string as mentioned in the gotcha above. Since no parameters are specified, it then creates a database “aspnetdb” with all the role tables. This is not quite what I want, as I need these added to my application database.

The answer is to use the command line:
aspnet_regsql -S -E -A all -d

If you run SQL Management Server Studio Express before and after - not forgetting to hit ‘refresh’ - then a bunch of new tables are added: aspnet_Applications, aspnet_Roles, aspnet_SchemaVersions, aspnet_Users, aspnet_UsersInRoles etc. Now it is just a matter of hooking those up with the application tables.

Since I wanted membership and roles as well as basic authentication I used the “-A all” option to add everything in. Of course I get profile and web-part support too with this, but I may choose to exploit such features in the future.

→ No CommentsTags:

Streamlining your PC to play games

December 29th, 2006 · Computer Games

Overview

Before I run a resource intensive game, I execute a little batch file that kills a bunch of background processes that are simply not needed when playing the game. I’ll explain the details below.

I have also noticed that before I used to do this, I experienced awful crashing problems with my PC just locking when playing. Since killing these extraneous processes, however, I have not had a single in-game crash that I used to get regularly with both BF2 and BFV. I think this shows that something in my system is having a bad interaction with the game - probably the graphics driver. I used to think it was an interaction with Panda antivirus, but recently I modified the script to not kill Panda and things still run OK. This makes me a little happier that I can keep my AV program running at all times.
[Read more →]

→ 1 CommentTags:

Gotcha on setting up a data connection

December 29th, 2006 · ASP2, Software Development

This one gets me every time. When you set up a new data connection to a database running on a local copy of Sql Server Express, in the “Add Connection” dialog you need to prefix your machine name to the defaulted value of “SQLEXPRESS”. E.g. if the network name of your PC is called “devpc”, then the connection string is:

  • DEVPC\SQLEXPRESS

While this is the obvious choice and works for many circumstances, a subtle variation is to use the following instead:

  • localhost\SQLEXPRESS

This now points the connection to an instance of SQL Server Express running on your local machine. If working in a team where each developer needs their own local copy of a database, then setting this in the web.config file can be a real help.

→ No CommentsTags: