locked
Attach MDF File from a network path. RRS feed

  • Question

  • Hi,

    I have installed SQL Express in one of the LAN system and having attached database with it.

    How do i access or attach same database from another system which are in LAN.

    Any help is appreciated.


    K K Sanghi
    Wednesday, January 18, 2012 11:45 AM

Answers

  • hi,

    you can do it in c# code exactely the same way you do it in SSMS... just execute the provided SQL statement via an ado.net command object and you'll be fine..

    as regard permissions, you should grant the (domain\)account running the SQL Server service "full control" on the remote share... http://msdn.microsoft.com/en-us/library/ms143504.aspx

    please consider that SQL Server is not "Access" and you should not manage databases as Access does.. Access is a file based database engine, where SQL Server is not (or not completely, of course)... the link provided by Vishal indicates all the considerations about "not doing this way", and you should trust them...

    regards


    http://www.asql.biz - DbaMgr2k - DbaMgr and further SQL Tools http://www.hotelsole.com/
    • Proposed as answer by Peja Tao Friday, January 20, 2012 4:49 AM
    • Marked as answer by Peja Tao Wednesday, January 25, 2012 1:29 AM
    Thursday, January 19, 2012 12:19 AM

All replies

  • Hi,

    Try this

    USE [master]
    GO
    CREATE DATABASE [AdventureWorks2008R2] ON
    ( FILENAME = N'\\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008R2_Data.mdf' ),
    ( FILENAME = N'\\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\AdventureWorks2008R2_Log.ldf' )
     FOR ATTACH
    GO
    


    Where the \\program files .... is your network path (\\) is important.

     

    I hope this is helpful.

     

    Elmozamil Elamir

    MyBlog


    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid
    http://elmozamil.blogspot.com
    Wednesday, January 18, 2012 12:12 PM
  • By default, network files are not enabled in SQL Server; you will have to add trace flag 1807.

    Description of support for network database files in SQL Server


    - Vishal

    SqlAndMe.com

    Wednesday, January 18, 2012 12:38 PM
  • Hi,

    I am getting following error :

     

    Msg 5110, Level 16, State 2, Line 1
    The file "\\Program Files\Microsoft SQL Server\MSSQL.3\MSSQL\Data\AdventureWorks_Data.mdf" is on a network path that is not supported for database files.


    K K Sanghi
    Wednesday, January 18, 2012 4:20 PM
  • Thanks for the reply.

    I am able to attach mdf file from a network share.

    But how i will do through my C# Code.

    Also what permission i need to add in share folder so that i can connect it from another system.

    Regards,

    Sanghi


    K K Sanghi
    Wednesday, January 18, 2012 4:57 PM
  • hi,

    you can do it in c# code exactely the same way you do it in SSMS... just execute the provided SQL statement via an ado.net command object and you'll be fine..

    as regard permissions, you should grant the (domain\)account running the SQL Server service "full control" on the remote share... http://msdn.microsoft.com/en-us/library/ms143504.aspx

    please consider that SQL Server is not "Access" and you should not manage databases as Access does.. Access is a file based database engine, where SQL Server is not (or not completely, of course)... the link provided by Vishal indicates all the considerations about "not doing this way", and you should trust them...

    regards


    http://www.asql.biz - DbaMgr2k - DbaMgr and further SQL Tools http://www.hotelsole.com/
    • Proposed as answer by Peja Tao Friday, January 20, 2012 4:49 AM
    • Marked as answer by Peja Tao Wednesday, January 25, 2012 1:29 AM
    Thursday, January 19, 2012 12:19 AM