Posts Tagged ‘Workarounds’

Why I’m not posting how to get .NET 4.0 working in Windows 2000

Tuesday, August 3rd, 2010

The most popular part of my blog is the posts that I have made on how to get .NET 3.5 (partially) working in Windows 2000, so why am I not continuing this with .NET 4.0?

The truth is that I originally did the .NET 3.5 approach for a specific project where a client of mine had a large number of Windows 2000 PCs. I wanted to be able to use .NET 3.5, and I didn’t want him to be saddled with the upgrade costs. However, since then, he has been gradually replacing those PCs with Windows XP and now Windows 7 PCs, until he only had 2 or 3 Windows 2000 machines left. I recommended to him that it was better for him to upgrade/replace the last ones rather than me trying to get .NET 4.0 working on the old ones, which probably wouldn’t be as cost efficient.

I realise that this might be a disappointment to some people who have still got lots of Windows 2000 machines out there. If anyone does come up with a way of doing it (possibly based on my .NET 3.5 approach), please let me know and I’ll post it up, crediting you.

Re-attaching SQL Server 2008 databases with Filestreams in a different path

Wednesday, July 7th, 2010

I’ve recently been moving servers and when I moved the databases, I was unable to re-attach them with a different path for the filestream folder.  The following blog post has a solution –

The Rambling DBA: SQL 2008 Filestream and Attach Database.

Getting the ASP.NET Development Web Server to use a root path

Friday, July 10th, 2009

ASP.NET 2.0 comes with a test webserver which can be run by simply pressing F5 in Visual Studio from a website project which is located on your PC.  The only problem is that for reasons best known to Microsoft, it launches with the site configured in a subfolder.  This isn’t always convenient, as you may have paths relative to the site root which prevent this being practical for testing.

In order to get around this problem, you need to take the following steps: –

First of all, configure Visual Studio so that you can launch the test server manually as follows: –

Under the Tools menu, select External Tools.
Add a new entry
Call it something like ASP.NET Development Server
Command is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE (you may need to alter the path for your local machine)
Arguments are /port:80 /path:$(ProjectDir) (note that you will need to leave a space on the end of this for it to work properly.  Also, you can change the port number if you wish)

Press OK.  You can now launch the development server from the new entry on your Tools menu.  This will show in your system tray.  You should probably remember to close it when you are done.

The next step is to configure your project to use the server.  Right click on your project and click Property Pages.  If an empty dialogue comes up, press cancel and repeat the process – it should work second time.  Under Start Options, select Use custom server and leave the Base URL blank.  You may wish to change the start action as well.

Once you are done, you can press F5 to start debugging.  Don’t forget that next time you open the project you will need to start the server from the tools menu before you start debugging again, otherwise it won’t work.

Also, bear in mind that if this is a copy of a remote site, things like database connection strings may need changing.  Don’t forget to be careful not to overwrite any settings when you copy back if that is the case!

If you do want to develop on a copy of the site, the Website menu has a useful option to Copy website.

.NET for Linux or Other Platforms – Novell Mono

Friday, July 10th, 2009

Whilst most of my work is done in VB.NET for Windows client and server PCs, I do also have a Linux server which I mostly am stuck coding in php on.  It would be nice if it were possible to code in .NET on it, and this is actually partially possible.

Novell have been working on a project called Mono over the last few years to create an alternative implementation of .NET for other platforms, including Linux.  They have implemented most of the major features and classes, but there are still a few areas which are patchy.  I usually find that the Handles VB.NET keyword doesn’t work and causes a compiler error, but it is quite possible to make a decent site that operates on Mono.  I’ve even compiled a DLL file in Visual Studio and used it in a Mono project’s Bin folder.  Of course if you do that, you have to be careful only to reference classes which are available in Mono.

FrontPage Server Extensions in Windows 2008

Friday, July 10th, 2009

As I mentioned in a previous post, I am currently in the process of switching to a One and One dedicated Windows 2008 x64 Server.   I was trying to work out how to set up FrontPage Server Extensions, which I’m not a big fan of, but I do find them very useful for editing remote sites directly through Visual Studio and my life would be a lot more difficult without them.  The problem is, I couldn’t find any reference to FrontPage Server Extensions anywhere in IIS7.

After a bit of research, I found that Microsoft no longer support FrontPage Server Extensions in Windows Server 2008 as they have replaced it with WebDAV, which seems technically much better.  The problem is that WebDAV isn’t supported directly by Visual Studio (please sort that out Microsoft!), so the only way of using that is to use WebDAV Redirector so that you can map a network drive for the folder and then access the network drive from Visual Studio.  This is not really a practical solution for me as I would have dozens of sites to keep track of and I don’t have the patience to remap them when I need them or keep track of so many different drive letters!

A quick hunt around online for an alternateive gave me Ready to Run Software’s site, which frankly looks suprisingly unprofessional if you believe that they are actually working with Microsoft.  I don’t know whether they are or not, but they do seem to be the sole supplier of a ported version of FrontPage Server Extensions for Windows Server 2008.

All credit to them, their port of it does seem to work, although I did get an error “unable to read configuration for Microsoft Internet Information service” when I tried to install it, but their FAQ deals with that.  I managed to get it working, although it is a real pain in the neck that you have to be logged in as Administrator and not just an administrator!

The problem I had was managing the FrontPage settings for the website itself – I wanted to add another user.  I couldn’t seem to log in to the site admin – it wouldn’t authenticate me whatever username I used or whoever I made the web administrator.   The only solution I found was to use owsadm.exe, which took a bit of hunting around for how to do it.

First of all, I found it in C:\Program Files (x86)\Common Files\microsoft shared\Web Server Extensions\50\bin\

Secondly, I needed to work out how to call it.  It isn’t very well documented, but you need to do something like this…

owsadm -o roleusers -c add -u username -m domainname -web /subweb -name Admin

replace username and domainname as appropriate, and /subweb with the path to the subweb that you want to add the user to.  That can just be / for the root web.  You can replace Admin if you don’t want to use the administrative role for your new user.  I’m not sure what the other role names are.

Linq to SQL Quirks Part 4: Circular References

Friday, July 10th, 2009
This entry is part of a series, Linq to SQL Quirks»

In a project that I am working on at the moment, I have a situation where I have a Person table and a Family table.  The Person table has a FamilyID field, which is a foreign key to the Families ID (primary key) field, and the Family table has a DefaultPersonID, which is another foreign key back to Person to store the default contact for a family.

The problem is that if I create a new Person and Family with the Person being the DefaultContact, I get an InvalidOperationException thrown with a message “A cycle was detected in the set of changes”.  The problem is that Linq to SQL doesn’t know what to store first.  The only way that I have come up with to get around this is to do the following…

            If Person.ID = 0 AndAlso Not Person.Family Is Nothing Then
                Dim fam = Person.Family
                Person.Family = Nothing

                Person.Family = fam

            End If


This works by breaking the circular reference, so that there is only a 1 way reference, then submitting to the database, and once submitted, restoring the removed reference and submitting changes again

Installing SQL Server 2008 x64 on Windows 2008

Friday, July 10th, 2009

I’m just in the process of switching my Windows Server from a Windows 2003 Server on Fasthosts to a Windows 2008 x64 one on One and One, who are offering me a much better deal.  Anyway, I’ve been having some interesting problems installing SQL Server 2008 Express on it.  I mean, it didn’t help that I didn’t realise that the server was preinstalled with SQL Server 2005 Express, but it surely shouldn’t be that hard.  I’ll skip to the point where I had uninstalled 2005 and was trying a fresh install of 2008…

First of all, I tried the Microsoft Web Platform Installer, and it died with an error saying “The INSTANCESHAREDWOWDIR command line value was not specified”.  I thought that this would be easily fixable if I just ran the installer myself, so I tried that.  It seemed to be going fine until I got to the page where I needed to specify what features I wanted to install, and there were 2 textboxes to specify folders at the bottom – one for the x64 main folders and one for the x86 WoW components (that’s Windows on Windows – not any other WoW you might have been thinking of).  The problem was that the main one was disabled (greyed out) and was trying to install to the Program Files (x86) folder instead of the Program Files folder.  When I tried to go to the next page, I got the same error.

I found that if I changed the x86 path, it would let me continue, but I didn’t want the main folder being installed wrong, so I followed through the installer to the Ready To Install page and at the bottom of the page there is a configuration file path.  I copied the config file and edited it to change the paths and then used the command line to launch the process using /action=install /configurationfile=configfilepath /q .

This seemed to work, but I had made a mistake with the configuration file (wrong instance name) and couldn’t be bothered going through the whole procedure again, so I called setup with all the parameters on the commandline.  Microsoft have documentation on what they all are.  It took some experimentation, but I think I used something like

/action=install /q /indicateprogress /features=sqlengine /installshareddir=”c:\program files\microsoft sql server” /installsharedwowdir=”c:\program files (x86)\microsoft sql server” /instancename=MSSQLSERVER /securitymode=”sql” /SAPWD=sysadminpassword

… and that seemed to work.

I’m not sure what Microsoft are playing at with this installer though.  It took me a good few hours to work this out and with a number of different permutations I tried, it just dropped out with no error message!  Also, the error is wrong – it specifies INSTANCESHAREDWOWDIR, which isn’t a parameter.  They actually meant INSTALLSHAREDWOWDIR.

Linq to SQL Quirks Part 3 – Extension to Get Around the Delete Problem

Tuesday, June 30th, 2009
This entry is part of a series, Linq to SQL Quirks»

My previous post about problems deleting can be partly handled with an extension method to the Linq to SQL Table(Of T) class with something like this…

         Public Sub DeleteOnSubmitOrDetach(Of T As Class)(ByVal table As System.Data.Linq.Table(Of T), ByVal o As T)
            Dim IDProperty = o.GetType.GetProperty("ID")
            If IDProperty Is Nothing Then
                Throw New System.MissingFieldException("Trying to delete object of type " & GetType(T).Name & " - does not have an ID field")
            End If
            If IDProperty.GetValue(o, New Object() {}) = 0 Then
            End If
        End Sub

Note that you’ll need to import System.ComponentModel and System.Reflection and possibly some others, and it assumes that you have an IDENTITY ID field by that name on all of your classes that you use this with.

Setting the .NET WebBrowser Control’s DocumentText Property

Tuesday, June 30th, 2009

The .NET framework comes with a nice WebBrowser control, which is a wrapper around MS Internet Explorer.  The problem is that it can be rather quirky at times, and one of these times is when you try to set the DocumentText property from code.  It might work, and then again it might not.  It is quite difficult to pin down exactly when it does work and when it doesn’t, but the following bit of code seems to set it for me…

  wbMsg.AllowNavigation = False
        wbMsg.AllowNavigation = True

        If wbMsg.Document Is Nothing Then
            wbMsg.DocumentText = s
        End If

More details on installing .NET 3.5 in Windows 2000

Wednesday, April 22nd, 2009

I’ve had a comment that my previous post explaining how to install .NET 3.5 in Windows 2000 wasn’t very clear, so I’ll try to clarify it a little…

First of all, let me explain how it works.  .NET is actualy 2 separate things.  There is the .NET runtime, which deals with interpreting the MSIL intermediate code and executing it.  There is also the .NET Framework, which are all the libraries containing the classes that you usually code with in .NET.

In theory, the .NET runtime can be used without the .NET framework (although you’d probably need a couple of DLLs to define things like the basic types).  You could use an entirely different framework which sits on top of the same runtime and is compiled to MSIL.  I’m not aware of any that exist though.

The really interesting bit is that there are actually only 3 versions of the .NET runtime – 1.0, 1.1 and 2.0.  1.0 and 1.1 are used for the corresponding framework versions, but 2.0 is used for running framework 2.0, 3.0 and 3.5.  

In fact, in terms of the framework, 3.0 is 2.0 plus some extra stuff, and 3.5 is 3.0 plus extra stuff.  The trick which I rely on is that you can install 2.0 in Windows 2000 and just add the extra stuff that you need. 

For my purposes, all I needed was support for Linq and Linq to SQL and a few other bits and bobs.  All this is available in .NET Assembly DLL files.  you just need to make sure that the assemblies are available to be loaded by the application you are running.  

You also need to make sure that you have any prerequisites for those assemblies, because a lot of them will access classes in other assemblies.  There are 2 ways of dealing with that.  You can either copy in the entire set of DLLs, or you can keep running your program and looking to see what assembly it can’t find when it throws an exception, copying that DLL in and re-running it until you don’t get any more exceptions.

There are 2 ways of making the assemblies available to your program.  You can either register them in the GAC so that they can be accessed from anywhere (I’ve not tried this and I probably wouldn’t recommend it – if you want to know how to do this, google installing an assembly in the GAC), or you can just copy them into the application folder that your EXE sits in (or bin folder on your ASP.NET website will probably work too).  This does make for a lot of files in that folder, but it works!

You should be able to find the .NET 3.5 assemblies in a folder on a PC that has .NET 3.5 installed under

Program Files\Reference Assemblies\Microsoft\Framework\v3.5 

nb. Make sure that you have Windows 2000 SP4 and .NET framework 2.0 SP1 installed on the Windows 2000 PC!  You might also need to install KB 835732 before .NET 2.0 SP1.