Determining if .mdf needs an .ldf to attach
I want to be able to look at a .mdf before trying to attach it and determin开发者_开发技巧e if it will be possible to attach it without it's .ldf (this can be done if it was detached correctly).
Currently, I am trying to attach the .mdf and if it was detached incorrectly and needs the .ldf to reattach it will give an error message that isn't very helpful to our user. I'd like to be able to give them a better error message.
You should only need the MDF file, but it changes the process.
This thread should sort you out.
It sounds like what you did was backed up the MDF file, and now you are trying to RESTORE it using the rESTORE command. That won't work.
To backup a database, you need to use the BACKUP DATABASE command, not simply copy the MDF file. The BACKUP DATABASE command makes a stable, reliable copy of the database which can be restored using the RESTORE command. Copying the .MDF file can work, but it has many more risks and I wouldn't recommend it.
To get the DB working with just the MDF file, execute the command:
SP_ATTACH_SINGLE_FILE_DB 'dbname','mdf file name' and, if it's at all possible, that will attach your database back. If it gives you errors, you're more than likely SOL on it, but pust them here and we'll try to help you.
精彩评论