change the location of mdf file and attach

Отвечено change the location of mdf file and attach

  • Thursday, May 10, 2012 8:32 PM
     
     

    hi i'm working with a vb.net project that works with a sql server database the database is currently not located in the program file i would like to transfer the mdf file to the vb project but when i transfer it i can not attach it to the server 
    i tried to open it by click the file and open with sql and it returned a error i tried with attaching with management studio but the three does not open till this file i don't know why 

    i tried the following command 

    CREATE DATABASE database_name
    ON
        (name = logical_file_name,
         filename = 'new file location')
    FOR ATTACH

    and i got the following error

    Msg 5133, Level 16, State 1, Line 1
    Directory lookup for the file "my file path" failed with the operating system error 5(Access is denied.).

All Replies

  • Thursday, May 10, 2012 9:38 PM
    Answerer
     
     Answered

    Hello Jacob,

    The reason it is failing is because of a windows permissions issue with the service account of SQL Server. In the error message, at the end you'll see it failed because the access to the file was denied by the OS. Give the correct windows level permissions (Read, write, list contents, execute) on the folders and files and try it again. The correct permissions are needed on both the files and folder for the current location as well as the new location. The permissions should be given to the database engine service account.

    -Sean


    Sean Gallardy, MCC | Blog

  • Monday, May 14, 2012 10:07 AM
     
     

    Hi could you please check this, it may help you out.

    http://blog.sqlauthority.com/2010/04/26/sql-server-attach-mdf-file-without-ldf-file-in-database/