Attaching to a SQL Express db using the connection string

Posted on 2006-05-09
Last Modified: 2012-05-05
does anybody has experience in attaching a .mdf sql express db file using the connection string ?

I am trying a thing as so:

<add key="CONNECTION_STRING" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|file_path|\mydbname.MDF;Integrated Security=True;Initial Catalog=mydbname;" />

but I am unable to connect.

I am using 1.1

Any help is veeery welcome because it is urgent!

Question by:NetDeveloper
    LVL 15

    Expert Comment

    Try dropping the AttachDbFilename, also add the userid and password. Add in a DataBase key as well
    LVL 10

    Author Comment

    Hi GavinMannion, tnx for ur Reply...u say to remove AttachDbFilename ? but at the provider I do not have the db restore...I just have that file.
    LVL 15

    Expert Comment

    Hmm sorry I was not paying full attention...

    taken from

    #   Attach a database file on connect to a local SQL Server Express instance:
       - or -
       (use |DataDirectory| when your database file resides in the data directory)

        Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).

    LVL 10

    Author Comment

    Hi, I get the error:

    System.Exception: Unable to get connection.General network error. Check your network documentation
    LVL 15

    Accepted Solution

    Can you access the SQLExpress database using the SQl Server Managment tool on that server?

    Possibly the SQL server is rejecting incoming connections?

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now