How to upgrade a database from localdb/v11.0 to localdb/mssqllocaldb without errors?

Visual Studio says I need to upgrade the database file. So I to try to attach the database file again. But whenever I attach, I get the following error-

So how can I upgrade it? Thanks. 


Note: I have moved the database from one computer to the other. 


August 27th, 2015 8:11am

Hi Bhupinder,

According to my knowledge, the above error could occur when the database is corrupt. If you have backup of the database, you can follow the steps in this similar blog to restore the database to localdb/mssqllocaldb  instance.

However, if you dont have the backup, execute the following scripts to restore database.         

CREATE DATABASE [MATERIALSDB]

  ON (FILENAME = 'c:\wherever\ MATERIALSDB.mdf')

  FOR ATTACH_REBUILD_LOG;

If that fails, perform the following process and check if it works.

on your localdb/mssqllocaldb instance, create a database with a data file of the exact same size

shutdown SQL Server

rename the new database's mdf file, and paste the old one in its place

bring up the server and let the database attempt to be recovered and then go into suspect mode

put the database into emergency mode with ALTER DATABASE MATERIALSDB SET EMERGENCY

run DBCC CHECKDB (MATERIALSDB, REPAIR_ALLOW_DATA_LOSS); which will rebuild the log and run full repair

There is a similar thread for your reference.
http://dba.stackexchange.com/questions/42762/how-to-attach-an-mdf-file-that-was-not-properly-detached/42807#42807

Thanks,
Lydia

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 6:43am

Hi Lydia

Thanks for the response. Sorry for the delay in responding. I have got an intact copy of the database before attaching it to localdb/mssqllocaldb. It works fine if I open it through v11.0. I've tried many times to detach it from v11.0 and attach it to localdb/mssqllocald. In doing so, the database came up with above error. There might be something wrong with the structure of the database that localdb/mssqllocaldb doesn't like. I had many other databases that I'd transformed fine. 

Is there any other way that I could attached it without getting the error? I have a copy of the database that works fine in v11.0, hence, not corrupt. 


September 3rd, 2015 6:14am

Hi Bhupinder,

Could you please back up the database firstly in localdb/V11.0 instance and then restore it in localdb/mssqllocaldb instance? The database should also work properly in Visual Studio after being restored to localdb/mssqllocaldb.

Thanks,
L
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2015 3:40am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics