none
How to connect to a sqlserver2005 database which was not attached RRS feed

  • Question

  •  

    Hi all,

    I have placed a sqlserver2005 database  in my local drive "c:\MyDataBase" which contains the log file and mdf file.

    The database files are not attached to the Sql Server 2005 Enterprise Edition. Now I have to connect to this Database with my C# application. How can I do this.

     

    Please help me out.

     

    Friday, November 30, 2007 11:42 AM

Answers

  • Hi,

     

    You can also use the AttachDbFilename of the connection string:

     

    Data Source=.\SQLEXPRESS;AttachDbFilename:c:\MyDataBase\mydb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

     

    Regards,

    Charles

     

    Saturday, December 1, 2007 12:35 AM

All replies

  • Hi

    You will have to attach the database to the server using a SQL statement before you will be able to use the database. Have a look at pinaldave's blog http://blog.sqlauthority.com/2007/08/24/sql-server-2005-t-sql-script-to-attach-and-detach-database/




    Friday, November 30, 2007 7:27 PM
  • Hi,

     

    You can also use the AttachDbFilename of the connection string:

     

    Data Source=.\SQLEXPRESS;AttachDbFilename:c:\MyDataBase\mydb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

     

    Regards,

    Charles

     

    Saturday, December 1, 2007 12:35 AM
  • Hi Charles,

    Your connection string seems pretty good and works well for me. And more connection strings info can be viewed from http://www.connectionstrings.com/?carrier=sqlserver2005.

    Here I still have a question, this soultion works for the database already detached from SQL Server2005, how do I connect a database which is not detached?
    Any help will be great appreciated.
     
    Regards
    Jing
    Friday, May 30, 2008 6:17 AM