Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2003
    Posts
    17

    Unanswered: How to connect mdf database?

    Hello guys!

    I'm really a newbie in sql stuff, but I have an mdf
    file and I need to get the data from there to excel
    (xls or csv). I have installed mssql server desktop
    edition and I need to connect my mdf database to
    server. How can I do this. I know there is some thing
    called sp_attach.... but how can I use it? I REALLY NEED
    A DETAILED EXPLAINATION. Information that "use
    sp_attach...." does'nt help me.

    Pleeeeeeeaase help me,
    Jessica

  2. #2
    Join Date
    Sep 2003
    Posts
    5

    Re: How to connect mdf database?

    well you can use sqlserver enterprise manager right click on databases all tasks, attach database or use a stored procedure:


    EXEC sp_attach_single_file_db @dbname = 'pubs',
    @physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf'

    to detach dabase :
    right click on database name all tasks, detach database

    or using stored procedure

    EXEC sp_detach_db @dbname = 'pubs'

    example are from books online

    bye




    Originally posted by Jessica7
    Hello guys!

    I'm really a newbie in sql stuff, but I have an mdf
    file and I need to get the data from there to excel
    (xls or csv). I have installed mssql server desktop
    edition and I need to connect my mdf database to
    server. How can I do this. I know there is some thing
    called sp_attach.... but how can I use it? I REALLY NEED
    A DETAILED EXPLAINATION. Information that "use
    sp_attach...." does'nt help me.

    Pleeeeeeeaase help me,
    Jessica

  3. #3
    Join Date
    Sep 2003
    Posts
    17
    Thank you Hotwebber!

    I have opened SQL server enterprice and on the left panel
    I right-clicked on database and All tasks, but there are only
    backup database, restore database, import data and export
    data. But no database attaching. I'M STILL STUCK.

    Please help,
    Jessica

  4. #4
    Join Date
    Sep 2003
    Posts
    5
    did you try stored procedure ????


    Originally posted by Jessica7
    Thank you Hotwebber!

    I have opened SQL server enterprice and on the left panel
    I right-clicked on database and All tasks, but there are only
    backup database, restore database, import data and export
    data. But no database attaching. I'M STILL STUCK.

    Please help,
    Jessica

  5. #5
    Join Date
    Sep 2003
    Posts
    17
    I don't know how to use this stored procedure.
    Can you give me an exaple when I have a
    file called database.mdf on my d:\ root directory

    Jessica

  6. #6
    Join Date
    Sep 2003
    Posts
    17
    I don't know why but it says that I don't have any privat messages,
    so I did'nt see your previous message also

  7. #7
    Join Date
    Sep 2003
    Posts
    5
    if you know original db name substitute MyDatabase in the sp command:

    open sql query analizer this can be done from enterprise manager Tools or start - programs microsoft sql server - query analizer
    paste the command

    EXEC sp_attach_single_file_db @dbname = 'MyDatabase',
    @physname = 'd:\database.mdf '


    press F5 or click the green triangle

    Hotwebber

  8. #8
    Join Date
    Sep 2003
    Posts
    17
    Sorry for being so dumb, but how can I know "original db name"? I only have one file called database.mdf

    Jessica

  9. #9
    Join Date
    Sep 2003
    Posts
    5
    try using MyDatabase as name

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •