none
How to connect SQL Server file (.mdf) in Visual Studio

    Question

  • Im trying to connect a SQL Server file named mybookstore.mdf, i've created this file in a MS SQL Server 2008 Express on the server named SQLEXPRESS

    when I open Visual Studio and tried to connect to it(assuming im on a project), VS cannot find my server instance when I tried to connect to it(connect to server) in the  Server Explorer, i tried typing localhost\SQLEXPRESS but it throws a message that it cannot be found

    i've also tried to open my database using the connect to database button on the Server Explorer but it ask me if I want to create it?

    how do I connect to my sql server file or database in visual studio 2008 if i've created the server file in the SQL Express Edition 2008?

    By the way, im only using 1 computer,, so im referring to the file locally.
    The point here is, I want to connect to a database from an SQL Server Instance.

    Can any one help me out?
    and also, the services.msc shows that the instance of SQLEXPRESS is running(started)
    Thursday, October 29, 2009 11:27 AM

Answers

  • Guys I appreciate all of your help, but I got the solution..

    I've reset the data source from the data source window to others and select the data provider manually.
    • Marked as answer by SheenLim Friday, October 30, 2009 9:53 AM
    Friday, October 30, 2009 9:52 AM

All replies

  • Attach a database file on connect to a local SQL Server Express instance
    Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname; Trusted_Connection=Yes;

    Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
    Provider=SQLNCLI10;Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;


    This is copied from this page
    http://www.connectionstrings.com/sql-server-2008#p1

    Success
    Cor
    Thursday, October 29, 2009 11:56 AM
  • Use (local) instead of localhost or the instance example posted by Cor.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, October 29, 2009 2:32 PM
  • I cant connect to my database using the connection string you gave me.
    It says that I do not have enough permission.
    Friday, October 30, 2009 9:28 AM
  • Guys I appreciate all of your help, but I got the solution..

    I've reset the data source from the data source window to others and select the data provider manually.
    • Marked as answer by SheenLim Friday, October 30, 2009 9:53 AM
    Friday, October 30, 2009 9:52 AM