Urgent -- need to attach database but don't have ldf

Posted on 2004-11-19
Last Modified: 2008-02-01
A client sent me xxxx.mdf without the associated xxxx.ldf.  Is there any way to go ahead and attach this database?

I tried creating my own xxxx database, which of course created an xxxx.ldf, then detached it.  Then I tried to attach the correct xxxx.mdf w/the newly created xxxx.ldf, and of course that didn't work.

Can this be done?

Question by:gary_j
    LVL 95

    Assisted Solution

    by:Lee W, MVP
    This may have an answer for you if you have or acquire an account:

    Attaching a database that has missing log file,289625,sid13_cid604510_tax294863,00.html
    LVL 6

    Accepted Solution

    Attach the database using sp_attach_db (see BOL for syntax). If you are lucky, SQL will re-create the ldf file for you.
    LVL 50

    Assisted Solution


    sp_attach_single_file_db [@dbname =] 'dbname',
        [@physname =] 'physical_name'

    for cases when you don't have the ldf ...

    don't forget you still need to sort out the "orphaned" users once the database is created on your server.

    LVL 5

    Author Comment

    using this command:

    sp_attach_single_file_db @dbname = 'mydb',
          @physname = 'e:\sqldata\mydb.mdf'

    returns this error:

    Server: Msg 1813, Level 16, State 2, Line 1
    Could not open new database 'mydb'. CREATE DATABASE is aborted.
    Device activation error. The physical file name 'c:\sqllogs\mydb.ldf' may be incorrect.

    Seems it's looking for the ldf on its own ...
    LVL 6

    Assisted Solution

    Unfortunately, those functions only work if you user the dettach function before on the server!

    Have a look at:
    LVL 5

    Author Comment

    I split the points because the correct answer may well have been "it can't be done" but everybody tried.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now