Monday 30 November 2009

[Tip] Remove Password from Office 2003 document

At work we needed to get into change a password protected word document of which everyone had forgotten the password. To do this my colleague found a great tip for removing passwords.

Here it is

1) With the document open press F11 while holding down shift and alt (Alt-Shift-F11). This should launch the script editor in Word.

2) Next select the find option (or hit ctl-f), and run a find for the word "password." This should highlight something like this "32943208".

3) Delete the letters and numbers between the tags (in the above example this would be the 32943208).

4) Save the document in the script editor and close the window. You should now be back in your Word document.

5) From the "Tools" pull down menu, select "unprotect." Your document should now be unprotected.

This should work the same way for Microsoft Excel.

Great tip thanks to Ashley Kozaczek.

Saturday 14 November 2009

Sql Server 2008 Database Mirroring - Cannot Create Endpoint

We have been testing SQL Server 2008 for a while now. This weekend was the date set to move our main database to SQL Server 2008 and also create a mirror on original SQL Server. We did a side by side install of SQL Server 2008 on the original server, which had SQL server 2005 on it.

The move to SQL Server 2008 went fine. I did a database copy form SQL 2005 to SQL 2008 on both the principal and the mirror instances. I then made a backup of the database from the principal instance and restored it to the mirror in recovery mode. Then I did a log backup on the principal server and restored it to the mirror database and still left it in recovery mode.

Finally it came to setting up the mirror. I used the wizard and got all the way through. Between it cam to starting the mirror an error showed up stating that the end point on the original server couldn't be contacted.

Firstly I thought that there was a firewall issue. However on checking I found that Windows firewall was switched off on both server.

Then I realised the issue was to do with the fact that mirroring had originally been enabled on the mirror servers SQL 2005 instance. I had gone through all mirrored databases on SQL 2005 instance and removed all mirroring but some where SQL 2005 was still keeping hold of the default 5022 endpoint.

After a bit of Googling and "Books On Line (ing)" I found two SQL statements that showed the problem when ran on the master database.

FROM sys.tcp_endpoints t

FROM sys.database_mirroring_endpoints e

The two statements show mirroring endpoints for an instance.

I had to delete the lines related to mirroring on the SQL Server 2005 instance. Once this was done I was able to successfully start mirroring on SQL Server 2008 instance for our databases.

As with anything like this it is advisable to take a backup of your system before manually changing the master database

Friday 6 November 2009

Create ICA files (The easy way)

Citrix Splash Screen
At work we sometimes need to give users access to programs that are installed on a subset of the Citrix servers. We have always done this by creating an ICA file of the application.

The usual procedure was:

  • Log onto Citrix Web Interface browse to the correct application
  • Right click on the application icon
  • Click 'Save Target'
  • Save the ica file somewhere it can be found.
  • Open the ica file in notepad
  • Edit the line that say removeicafile=yes to removeicafile=no (so that the file isn't deleted after the first run).
  • And finally run the application

In XenApp it is a bit easier.

The procedure is as follows:

  • Open Access Management Console
  • Drill down to the application, fro which, you want to create ICA file.
  • Right click on the application icon
  • Choose All Tasks -> Create ICA file.
  • In the box that appears un tick the check box (if internal connection) and browse to a file location to save the file.

This file will be ready to deploy to the user.

Hope this helps someone.

Thursday 5 November 2009

Beautiful Code - Trailing zeros

Sometimes during the course of a day you come across something that makes you see how beautiful programming can be.

For example I was looking for a way of adding trailing zeros to a string however the string was variable length between one and five characters long and had to be a total of six characters long. Adding a set number of zeros wouldn't work because the variable length of string.

After a bit of searching I found the following beautiful code:

UPDATE SomeTable
SET SomeColumn = LEFT(SomeColumn + '000000', 6)

This code sets SomeColumn to be atleast 6 characters long by concatenating SomeColumn with six zeros. Then you chop off all characters except the first six characters using 'left' and you have the correctly formatted result string.

I think this is a beautiful way of adding trailing zeros to a string.

Please share your beautiful code