tags:

views:

2365

answers:

5

I got this error when I checked out my database from source control. It might sounds weird to check in the sql server database, but this was what I have done because this is just a personal project.

Anyone knows how to fix this?

+1  A: 

You really don't want to be checking database files into and out of source control - in SQL Server you have to detach the files for this to even work and you run all kinds of risks.

If you absolutely have to do this, you should version backups.

I recommend versioning a script which creates the entire database (tables, sprocs, views, etc.)

You can try creating a database attaching from that data file and using Create Database the ATTACH_REBUILD_LOG option, but I'm not confident it's going to work since they probably weren't detached properly.

Cade Roux
A: 

Did you take a copy of the log file (.ldf) as well as the ".mdf" file? You need the matching set of both to re-attach the database

Rob
A: 

This sounds like the data files do not match the structure files of your database.

Shortly spoken, the files where your data (i.e. table rows) resides in are (mostly) not the files the structure of your data (i.e. the description of the tables) is stored. At least in "modern" RDBMS systems. So you checked out your data and the database recognized some changes in the structure which happened till then (you altered a table or something like that).

The way "to fix this" would be to check in all files your database relies on, but I think that is not really what you wanted to achieve. Better (as mentioned above) to do backups and then drop / restore the database from them.

Georgi
A: 

Rob, I didn't check in the log file.

Ngu Soon Hui
A: 

Here's my finding.

As other posters mention, you really don't want to check database files into and out of the source control.

But if you absolutely need to, or you have done that and you are encountering the same error that I encountered, here is one workaround.

First, detach the database, then, delete the ldf file, reattach the database again.

This is how I solved my problem.

Ngu Soon Hui