Sql Server Reindex Tables

During my attempt to shrink my database so that it would fit on my laptop (it was 20 gigs), I figured out that I needed to reindex all my tables.  Usually the format of your data and log files will follow this pattern – just replace the {DATABASE_NAME} with the name of your database.

DBCC SHRINKFILE ({DATABASE_NAME}_data,5)

DBCC SHRINKFILE (
{DATABASE_NAME}_log, 1);
BACKUP LOG
{DATABASE_NAME} WITH TRUNCATE_ONLY;
DBCC SHRINKFILE (
{DATABASE_NAME}_log, 1);

Performance Counters and Security Exceptions

If you try to create a Performance Counter in ASP.NET, you will get a happy reply when you run it:

System.Security.SecurityException:
Requested registry access is not allowed.

Simply, the ASPNET account doesn’t have access to the Registry to create them.


There are several solutions, but the one I hear most is changing the context the ASPNET account is using in machine.config to use “SYSTEM” instead of the default “MACHINE”. This works, but opens up some security no-no’s.


The best fix that I found is to grant the neccessary permissions to the aspnet wp account (ASPNET) in the registry.



  1. Open regedt32 (not just regedit).
  2. Go to HKEY LOCAL MACHINE\System\CurrentControlSet\Services\EventLog
  3. Right click on “Security” and select “Permissions…” in the menu
  4. Add the ASPNET account for the local machine and place a check next to “Full Control”

  5. Restart IIS


If that doesn’t work, create a directory under \Services and call it the name of your performance counter you are trying to create. Then give the ASPNET account access to that.

Make a Hotkey Macro for Comments in .NET

I like having comments in the code that shows who did it and when. You can obviously get more complex, but this is good for me.

To make your own macro to look like “//SBE 06/04/2004: “, do this:

  1. Open Macro Explorer w/in VS.NET. (Tools –> Macros –> Macro Explorer)
  2. Create a function like the one below in any module. My example below uses a module called “Module1” (those are my initials BTW).
  3. Sub Comment()
    DTE.ActiveDocument.Selection.Text = "//SBE " +
    Date.Today.ToString("MM/dd/yyyy") + ": "
    End Sub
  4. Close Macro Explorer and go to Tools –> Options –> Environment –> Keyboard.
  5. Select your macro, like (Macros.MyMacros.Module1.Comment)
  6. Select “Global” or whatever you like, in “Use new shortcut in”
  7. Go To “Press shortcut key(s)” and select on your keyboard a combination. Mine is -Q. Hit “Assign”. If it is already in use, it will tell you to create your own mapping scheme. Just do it.
  8. Test it out in your code.

Update 5/19/05: For Visual Studio 2005, you will find the dialog at Tools –> Customize –> Keyboard…