An attempt to attach an auto-named database for file ... failed

Last post 10-05-2009 11:05 PM by chetan.sarode. 23 replies.

Sort Posts:

  • Re: An attempt to attach an auto-named database for file ... failed

    05-18-2007, 12:19 AM

    This is not depend upon what version you used...

    See in the App_Data folder or see in Server Explorer in VS, you will get there..

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: An attempt to attach an auto-named database for file ... failed

    02-09-2008, 9:39 PM
    • Member
      16 point Member
    • Mark Barnes
    • Member since 12-29-2006, 7:57 PM
    • Posts 44

    After a lot of trials, tribulations and errors, I found a solution to the problem.  Please mark this as an answer if it turns out helpful.  I cannot vouch for the security of this solution.  Some say its bad, but I say its good because it works.

     

    1. Update your connection string to the following: 

    Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

     Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.

    2. Under the application pool properties in the identity tab, set "Network Service" or "ASP.NET" as the security account.

    3. Make sure you grant read and write permissions to "Network Service" or "ASP.NET" account.  Give full permissions and adjust later to be on the safe (or unsafe) side.

     

    COMMENTARY: 

    The security model for .NET, ASP.NET, SQL Server, and Windows is extremely difficult to wrap your head around.  You must know each technology’s security model and how they interplay with one another in order to become proficient and productive.  The exception error messages don't really tell you what the problem is.  There are no books or articles that cover these security models comprehensively. Consequently, many developers figure out what works by trial and error and wind up compromising security, which renders the security system useless.

  • Re: An attempt to attach an auto-named database for file ... failed

    02-10-2008, 10:35 PM

    Try to set User Instance=false

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: An attempt to attach an auto-named database for file ... failed

    07-03-2009, 5:30 AM
    • Member
      257 point Member
    • garrygrimshaw
    • Member since 11-10-2006, 12:16 PM
    • Manchester, UK
    • Posts 60

    I've just had this same problem and figured out what the cause is.

    This error message is happening because the account which the Application Pool is running does not have sufficient permissions to auto-attach the database.

    Please note this is NOT the account which is used to run the website.  My Application Pool is the DefaultAppPool and was using Network Service account to run.

    I changed this to Local System and it started working.  However, I believe this has security implications which I cannot be bothered to figure out just yet.  I'm just happy it's working.

  • Re: An attempt to attach an auto-named database for file ... failed

    07-05-2009, 10:55 PM

     Yes thats right ,but recommondation is to use  Network Service account to run.

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: An attempt to attach an auto-named database for file ... failed

    07-10-2009, 11:28 AM
    • Member
      2 point Member
    • aebordones
    • Member since 03-07-2009, 11:10 PM
    • Posts 4

     THE MAIN PROBLEM IS THIS ERROR:

    "OR IT IS LOCATED ON UNC SHARE",  I REALLY DON´T KNOW WHAT'S THE PROBLEM, BECAUSE I´M NOT SHARING ANYTHING... IF YOU FIND SOMETHING... PLESE WRITE ME aebordones@hotmail.com

    Adrian E. Bordones B.
  • Re: An attempt to attach an auto-named database for file ... failed

    07-12-2009, 11:02 PM

     CAn you put here more error details here, So that it will be helpful to solve it

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: An attempt to attach an auto-named database for file ... failed

    10-02-2009, 1:56 PM
    • Member
      2 point Member
    • Taiwo Egun
    • Member since 10-02-2009, 5:52 PM
    • Posts 1

    Guys, if you are getting this error running it locally, Visual Studio provides the connection string that you can use. Go to Server Explorer-> and aright click on the name of the .mdf file. Click "Modify Connection..." and select "Advanced" at the bottom, there's a Textbox with the connection string. Use this if testing locally. When Deployed, change the "AttachDbFilename" to the deployed location. (i.e. "AppData/DBName.mdf". Hope this helps.

  • Re: An attempt to attach an auto-named database for file ... failed

    10-05-2009, 11:05 PM

    Another way to solve this query...Thanks

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 2 of 2 (24 items) < Previous 1 2