I set up a Windows Server 2012 virtual machine exactly the way we want it. I shut down the instance, made a copy of the .vhdx virtual drive, then spun up a new VM and attached the copy of the drive.

I started up the new VM and everything worked properly. Then I proceeded to run SysPrep on the new VM so it wouldn't clash with the original and I could run them both at the same time.

After running Sysprep I had to enter a CD-Key when I powered up the instance (expected behavior) and had to create an account for the new VM.

SQL Server Express was still installed and I was able to connect. However, whenever I try to expand a database I get an error message The database [DbName] is not accessible. (Object Explorer)

I also noticed that the SQL users I had created are now gone.

Does anyone know why this happened or how to recover?


The machine name gets changed during sysprep and SQL Server needs to be manually made aware of this. Try running this with sysadmin privileges:

sp_dropserver <old_name\instancename>;
sp_addserver <new_name\instancename>, local;

and then restart the SQL Instance. For SQL Express you will most likely need to replace instancename with sqlexpress.

Here is the TechNet article explaining renaming a host.

| improve this answer | |
  • I was able to log in as sa and run your recommended stored procedures to rename the instance. I still had the same issue when I use Windows Authentication and try to explore the database. The DBs show up, but when you go to expand they throw the error. There are only 2 users listed in the Security section. However, I logged in as sa and could explore everything and see all the users. Simply added a new user with the correct machine name with sysadmin privileges and it worked like a charm. Thanks. – Sam Oct 14 '13 at 22:06
  • @Sam The problem with Windows Authentication is probably also related to sysprepping the new machine. Windows Logins are identified by a SID (a unique security identifier) that would have changed during sysprep thus orphaning the logins. – squillman Oct 15 '13 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.