We help IT Professionals succeed at work.

sp_attach_db problem

1,295 Views
Last Modified: 2010-05-18
I successfully detached a database from the server so that I could dispose of the large log file that had filled up the disk.
I then proceeded to re-attach the database, using the following query in MSSQL Server 7
exec sp_attach_db @dbname = 'Stamps', @filename1 = 'D:\MSSQL7\Data\Stamps_Data.MDF'

this gives the following error, how can I re-attach the database ? ( I have double checked the file name and path)
I have also tried the following but get the same error
exec sp_attach_db @dbname = N'Stamps', @filename1 = N'D:\MSSQL7\Data\Stamps_Data.MDF'

Server: Msg 945, Level 14, State 2, Line 1
Database 'Stamps' cannot be opened because some of the files could not be activated.
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'Stamps'. CREATE DATABASE is aborted.

I have also posted in SQL 2005 because SQL server 7 is not listed in ee ?
Comment
Watch Question

Commented:
Aside from the fact that this is not the safest way to shrink your log file have you tried using the Enterprise Manager to attach the database?
Database Consultant
CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
aneeshattingal, I get the same error message when I use sp_attach_single_file_db ???
I have re-booted the server but still no luck. Is there any other way that I can restorre the database from the MDF file ?
Thanks,

Roger

Crag, There is no way of attaching a databse with Entrprise manager that ships with SQL server 7
AneeshDatabase Consultant
CERTIFIED EXPERT
Top Expert 2009

Commented:
Most Valuable Expert 2014

Commented:
If the ldf file is gone, at this point I think it is a lost cause.

I was never able to get a DB to attach with the MDF alone in SQL 7.

At this point your only real hope is to restore from backup.

For future reference change your database's recovery mode to 'Simple' and it will automatically truncate the transaction log.

Author

Commented:
aneeshattingal, I re-attached the database with sp_attach_db and the original log file that I had moved rather than deleted.
I then detached and then did sp_attach_single_file_db and it worked the second time.

Thanks for your prompt help, I can go home now !

Best tegards,

Roger

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.