Thursday, 29 January 2009

Sorting custom collections in C#

Take a look at Craig Gibbons' blog for a run-down on sorting custom collections.

Add a range of ports to Windows Firewall from the command line

To add a range of ports to Windows Firewall from the Command Line:

  • Click Start, click Run, type cmd, and then click OK.

  • Type in the following where the range is specified in brackets and the name you choose for the firewall entry is in double quotes.
    FOR /L %I IN (5001,1,5201) DO netsh firewall add portopening TCP %I "Passive FTP"%I

  • Each port in the range will be added with an "OK" confirmation.

Enabling Passive FTP on Windows 2003 with Windows Firewall

After much searching I have finally (!) located the best way of enabling passive FTP through Windows Firewall.

On Windows 2003 Server with IIS6
To Enable Direct Metabase Edit

  • Open the IIS Microsoft Management Console (MMC).

  • Right-click on the Local Computer node.

  • Select Properties.

  • Make sure the Enable Direct Metabase Edit checkbox is checked.


Configure PassivePortRange via ADSUTIL script

  • Click Start, click Run, type cmd, and then click OK.

  • Type cd Inetpub\AdminScripts and then press ENTER.

  • Type the following command where the range is specified in "..". cscript.exe adsutil.vbs set /MSFTPSVC/PassivePortRange "5001-5201"

  • Restart the FTP Publishing Service.
    You'll see the following output, when you configure via ADSUTIL script:
    Microsoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
    PassivePortRange : (STRING) "5001-5201"


Add each port to the Windows Firewall

  • Click Start, click Control Panel, open Windows Firewall, and select the Exceptions tab.

  • Click the Add Port button.

  • Enter a Name for the Exception and the first number in the port range.

  • Click TCP if not already selected and click OK.

  • Repeat for each port in the range - for large ranges see the end of the document.

  • Enable the Windows Firewall on the General Tab.


On Windows 2000 Server with IIS5 Configure PassivePortRange via Registry Editor

  • Start Registry Editor (Regedt32.exe).

  • Locate the following registry key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Msftpsvc\Parameters\

  • Add a value named "PassivePortRange" (without the quotation marks) of type REG_SZ.

  • Close Registry Editor.

  • Restart the FTP Publishing Service.
    Note: The range that FTP will validate is from 5001 to 65535.


Thank you to http://www.newagedigital.com/cgi-bin/newagedigital/articles/ms-firewall-ftp.html for the heads up.

Monday, 26 January 2009

Recover from corrupt SQL LDF transaction log file

Another favourite this month. A fault on one of our client's servers caused it to restart once every 10 minutes for 2 hours - the result was a corrupt LDF transaction log file for the main application database.

It is surprisingly simple to recover from this situation:

1. Stop the SQL Server service
2. Copy the affected database (both LDF and MDF files) out of the main data folder.
3. Restart the SQL Server service
4. Create a new database of the same name and location as the database affected in step 2 - it is critical the filenames and paths are identical.
5. Stop the SQL Server service.
6. Copy the original MDF file (copied in step 2) in to replace the new MDF file created in step 4
7. Start the SQL Server service - the database will show as being suspect.
8. Now you need to recover the database, working from Query Analyser or SQL Management Studio:

Use master
go

sp_configure 'allow updates', 1
reconfigure with override
go

select status from sysdatabases where name = '{{DBName}}'
go
-- Make a note of the status - in case you need to restore the value.

update sysdatabases set status = 32768 where name = '{{DBName}}'
go

9. Restart SQL Server - the database should now show up in emergency mode.
10. Delete the LDF file for the database.
11. Rebuild the transaction log:

DBCC REBUILD_LOG ('{{DBName}}', '{{Full path to the LDF file}}')
go
-- SQL Server will confirm: Warning: The log for database '' has been rebuilt.

12. If all appears to be OK:

USE {{DBName}}
GO
ALTER DATABASE {{DBName}} SET SINGLE_USER
go
DBCC CHECKDB ('{{DBName}}', REPAIR_ALLOW_DATA_LOSS)
go

13. If all still appears to be OK:

sp_dboption '{{DBName}}', 'single_user', 'false'
go

Use master
go

sp_configure 'allow updates', 0
go

Tuesday, 13 January 2009

IIS6 - which W3WP.EXE belongs to which application pool

Our servers run with a number of application pools to separate load between several intensive websites/processes. When everything is running fine management is easy but if an application pool begins to use excessive resource it is necessary to identify which W3WP.EXE process is using the resource and therefore which app pool is causing the problem.

Microsoft have provided a script file (.vbs) to list all W3WP.exe processess, the PID and the application pool. Simply open a command prompt (Start > Run, enter "cmd", click OK), type iisapp and hit return. Below is an example of the output:

W3WP.exe PID: 1468 AppPoolId: AppPoolForSite1.com
W3WP.exe PID: 3056 AppPoolId: AppPoolForSite2.com
W3WP.exe PID: 1316 AppPoolId: AppPoolForSite3.com

Thank you ASP Alliance for this one:
http://aspalliance.com/576

Shrink SQL Server Log File LDF

Having recently had a very intensive database with limited data generating a huge transaction log file (>4Gb for a 150Mb database) it was necessary to carry out a temporary truncate and then schedule once per day, the following prodecure is very effective:

USE {{DatabaseName}}
GO

DBCC SHRINKFILE({{FileName}}, 1)
GO

BACKUP LOG WITH TRUNCATE_ONLY
GO

DBCC SHRINKFILE({{FileName}}, 1)
GO