Error renaming database in SQL Server 2008

I right clicked on a database in SQL Server Management Studio and selected rename. Gave it a new name and hit enter. Eventually this error comes back:

Msg 5030, Level 16, State 2, Line 1

The database could not be exclusively locked to perform the operation.

The better way to rename the database is using SQL running these queries:

use master;
ALTER DATABASE [database.name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [database.name] MODIFY NAME = [database.name.old];
ALTER DATABASE [database.name.old] SET MULTI_USER;

How to check MD5 hash values for a file with a Microsoft tool

We have a lot of download sites blocked at work, so I’m not always able to just go and grab a utility when I need it. But I usually have access to all the Microsoft sites.  I needed to calculate some MD5 sums for a file on a Windows machine. You can do this with the Microsoft File Checksum Integrity Verifier or FCIV. The current version is from 8/22/2012.

The download is a zipfile that you can extract and it produces a .exe file and a readme. I put small utilities like this into a directory on my machine that’s easy to get to like c:\tools

Once you have the exe, you can follow the instructions of “How to compute the MD5 of SHA1 hash values for a file” or just use this:

fciv.exe -md5 path\to\file

Happy MD5 summing!

How to set an Orchard CMS module to be home page with code

This will work for Orchard CMS Version 1.8.

  • Create a new module
  • Create a Routes.cs file in the module
  • Set the RouteDescriptor priority to something high like 99
  • Set the new route url to be an empty string

Here’s some example code for Routes.cs

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;

namespace Newmodule
{
    public class Routes : IRouteProvider
    {
        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {

                new RouteDescriptor {
                    Priority = 99,
                    Route = new Route( 
			"",
                        new RouteValueDictionary {
                            {"area", "Newmodule"},
                            {"controller", "Home"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "Newmodule"}
                        },
                        new MvcRouteHandler())
                }



            };
        }
    }
}

TL-WA850RE has no internet access

TL;DR – Get the firmware update for the TL-WA850RE at http://www.tp-link.us/support/download/?model=TL-WA850RE&version=V1, unzip it and run the update from within the TPLink setup page.  This solves most problems.  The other handy thing is to change the SSID of this range extender by adding a “2” to the name of your original SSID.

I’ve got a TV that’s just out of range from my wifi router.  Yes, I know, I should get off my lazy butt and just run cat6 thru my whole place.  But in the meantime, I purchased a TP-LINK TL-WA850RE 300Mbps Universal Wi-Fi Range Extender.

I plugged it in and did a manual setup.  I could get devices to connect to it but it took a long time.  Once connected, each device had no internet access whatsoever.  Bummer.  I tried some different configurations of it but the thing that worked the best was just going to the TPLink download site and grabbing the latest firmware.  The firmware on my newly purchased device was like 2 years old.  I’m not sure why they ship it like that.

Once I updated to the latest firmware in the web-based tool for the TPLINK, it still didn’t work as smoothly as I would have liked.  The final two settings I did were under “DHCP” where I set a static IP to be one IP up from my wifi router.  I also tweaked the SSID put out from the TPLINK to have a “2” at the end of my original wifi SSID.

Once I did those three things, the wifi range extender worked to perfection.  I have a great fast signal far away from the wifi router.  It’s fast enough to stream Netflix adequately.

 

 

WordPress 3.9 – PHP Fatal error: Allowed memory size of XXX bytes exhausted

More WordPress 3.9 system administration issues.  Kept getting errors from WordPress once a couple of plugins were installed that looked like this:

PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 30720 bytes) in /var/www/wp-content/themes/x/framework/functions/global/admin/sidebars.php on line 166

According to Editing wp-config, the minimum memory required for WordPress 3.9 is 64mb.  You can do this by editing the php.ini file and increasing:

memory_limit = 64M

And then restarting Apache or Nginx.  Enjoy!

 

WordPress 3.9 Update plugin shows FTP connection screen

While working on a new wordpress install for a person in my group, I came across a problem when trying to upgrade plugins from within wordpress itself.  It kept showing an “FTP connection” screen.  Putting in valid ftp credentials for that server would fail with “Unable to connect” errors.  WTF?

It turns out there’s a magical wordpress config setting that you can add to wp-config.php:

define('FS_METHOD', 'direct');

This forces wordpress to use some another method of updating plugins besides FTP ( I don’t really know what method it uses at this point, should research that.)

 

tail -f equivalent on Windows

As a longtime Unix and Linux guy, I always find myself looking for similar equivalents in the Windows space now that I’m doing so much C# .net work.  One thing I do a lot is look at the end of log files from my applications to see what’s happening.  In *nix you can do something like:

tail -f logfile

which shows you the last few lines of “logfile” interactively.  Meaning, that it will sit there and wait until “logfile” is appended to and it will then show you those lines.  It’s great for monitoring something sticky deep inside an application if you don’t have tests you can generate and run.

An equivalent to “tail -f” on Windows is to use PowerShell with this command:

Get-Content logfile -wait

Another nicety in PowerShell “Get-Content” is that you can pipe the output to a search to only show the logfile lines that contain a specific string:

Get-Content logfile -wait | where { $_ -match "searchString" }

Happy tailing!

 

EntityType has no key defined. Define the key for this EntityType

While running “Add-Migration” I kept receiving the following error in a new ASP.NET C# project using Entity Framework.

 

Ebs.Job.Models.JobListing: : EntityType ‘JobListing’ has no key defined. Define the key for this EntityType. JobListings: EntityType: EntitySet ‘JobListings’ is based on type ‘JobListing’ that has no keys defined.

The code in question was the following:

public class JobListing
{
     [Key]
     public UInt32 Id { get; set; }

The answer is that as of 6/12/2014, Entity Framework does not support unsigned integers.  Once I changed the UInt32 to Int32, everything worked great.