Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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>;
GO
sp_addserver <new_name\instancename>, local;
GO

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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