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:

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

    04-22-2005, 2:47 PM
    • Member
      260 point Member
    • Rich21
    • Member since 12-31-2004, 3:47 PM
    • Jacksonville, Florida
    • Posts 52

    When I attempt to run the Time Tracker Starter kit I receive the following error:

    An attempt to attach an auto-named database for file C:\WebSites\Test_TimeTracker\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

    I checked SQL Express and I did originally have a database named aspnetdb that was installed by the QuickStarts. I have subsequently detached that database and moved the data and log files from SQL Express's data folder, however I still get the same error.

    I've opened mdf file in visual studio and verified that it did indeed contain data and was not corrupt.  The directory is not in a UNC Share.  I've granted full security access on the WebSites directory to the "Everyone" user.

    I'm running Windows 2003 Standard Edition, using Visual Studio Team Suite, running under beta 2 of the Framework.

    I imagine that I could attach the mdf in Sql Express and then rewrite the ConnectionString to point to that, but I'd like to get it to work the way it was intended.  I've attached the Connection String section as well as the stack trace below. Does anyone have any ideas about how to fix this issue?

    <connectionStrings>
     <add name="aspnet_staterKits_Test_TimeTracker" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
     <remove name="LocalSqlServer"/>
     <add name="LocalSqlServer"connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
    </connectionStrings>


    [SqlException (0x80131904): An attempt to attach an auto-named database for file C:\WebSites\Test_TimeTracker\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +684979
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +207
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1751
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +32
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +601
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +159
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +346
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +445
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +304
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +85
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
       System.Data.SqlClient.SqlConnection.Open() +111
       System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +126
       System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +226
       System.Web.Security.SqlRoleProvider.RoleExists(String roleName) +467
       System.Web.Security.Roles.RoleExists(String roleName) +196
       ASP.Global_asax.Application_Start(Object sender, EventArgs e) in c:\WebSites\Test_TimeTracker\Global.asax:13

    -Rich

    Rich Czyzewski

    Software Architect
    Jacksonville, Florida

    Check out my .NET 2.0 Website WebJots (Starter Kit Available)
    My Blog - Beta 2 Stuff, ASP.NET, etc.

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

    04-22-2005, 4:00 PM
    • Member
      260 point Member
    • Rich21
    • Member since 12-31-2004, 3:47 PM
    • Jacksonville, Florida
    • Posts 52

    I figured it out.  I took a look at the connection string on the personal web site starter kit which is similar in the way that it connects to the database.

    Apparently the Time Tracker Starter kit is missing the following option from its connections string.

    "User Instance=True;"

    Once I added this option to the Connection String everything works fine.  So the new connectionstrings look like this.

      <connectionStrings>
        <add name="aspnet_staterKits_Test_TimeTracker"
             connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
        <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer"
             connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
      </connectionStrings>

     

    Rich Czyzewski

    Software Architect
    Jacksonville, Florida

    Check out my .NET 2.0 Website WebJots (Starter Kit Available)
    My Blog - Beta 2 Stuff, ASP.NET, etc.

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

    05-02-2005, 6:18 PM
    • Member
      20 point Member
    • sjmac
    • Member since 05-02-2005, 5:20 PM
    • Posts 4

    Thanks for that Rich!

    That was one of the problems I was having when trying to run the app in my local IIS. After I changed the connection string, I got the same error message again, but this time with a different stack trace.

    Then I read your post again, and went to look at my databases with SQL Express Manager, and noticed that aspnetdb was already running in it. I deleted the aspnetdb,, reinstalled blank mdf files for it and the timetracker db, changed the permissions so that "Everybody" had full control to them, and then tested the app. I can now use it!

    Can anyone tell me what the user instance=true part of the connection string does?
  • Re: An attempt to attach an auto-named database for file ... failed

    05-08-2005, 11:22 AM
    • Member
      20 point Member
    • sjmac
    • Member since 05-02-2005, 5:20 PM
    • Posts 4
    Replying to myself :-)

    User Instance = true is described in this post on the MS news groups:
    http://communities.microsoft.com/newsgroups/previewFrame.asp?ICP=sqlserver2005&sLCID=us&sgroupURL=microsoft.private.sqlserver2005.express&sMessageID=%253CuQCkdV5UFHA.2092@CPMSFTNGSA04.privatenews.microsoft.com%253E

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

    03-30-2006, 12:26 AM
    • Member
      315 point Member
    • Xarain
    • Member since 09-02-2004, 1:49 AM
    • Posts 63
    doesnt work for me.

    <connectionStrings>
            <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
                providerName="System.Data.SqlClient" />
        </connectionStrings>


    my User Instance=True is there by default but still get the UNC error thingy.


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

    09-15-2006, 4:21 AM
    • Member
      59 point Member
    • Timeware
    • Member since 07-11-2006, 3:32 PM
    • Posts 21

    Hi,

    The only times I have received this message have been when, after testing on my local server with it working perfectly, I have moved the application onto a remote test server and placed the application in a subfolder of the remote site.

    This always generates this message.

    After the data has been moved to the correct location (as it would be on a live server) or the test server location is identified in the web.config file then the problem has been resolved.

    In each case the relevant part of the message was "or specified file cannot be opened" as it is being told to look in the wrong location.

    Hope this helps you.

     

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

    09-20-2006, 6:51 PM
    • Member
      249 point Member
    • porov
    • Member since 02-01-2006, 8:39 PM
    • Posts 75

    I had the same problem with my website freehosting1.net

    What i did to resolve it is to add a 'database' property to my connection string and delete the log file.

    But anyway i would like to note that sql server has alot of trouble giving you the right instructions to solve the probems,

    i mean the error messages gives u some info about it, but by far not enough to resolve it easily. 

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

    02-02-2007, 3:40 AM
    • Member
      106 point Member
    • raikkonen
    • Member since 09-29-2006, 9:43 AM
    • Posts 151

    I have the same error after a current failure(my pc shat down suddenly)...my connection string is ok and I don;t know what's going wrong...

    Any Ideas?

    Thanks!!!

     

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

    02-05-2007, 12:14 AM
    Answer

    raikkonen:

    I have the same error after a current failure(my pc shat down suddenly)...my connection string is ok and I don’t know what's going wrong...

    Any Ideas?

    Thanks!!!

     

    Hi, I'm wondering if there is corruption of the aspnetdb.mdf file because of improperly shutting down, Please make sure that the file is still exists under App_Data folder of your web application. If it is, make a copy of it, though it might be corrupt already.

     

    You can try attach your .mdf file with SQL Server. You can try to attach mdf only by using sp_attach_single_file_db too if there is only one ldf file for the db. 

     

    If you are using SQL Server instead of SQL Server Express, please back up the last transaction log too.

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;253817

     

    Zhao Ji Ma
    Sincerely,
    Microsoft Online Community Support

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: An attempt to attach an auto-named database for file ... failed

    02-05-2007, 11:24 AM
    • Member
      106 point Member
    • raikkonen
    • Member since 09-29-2006, 9:43 AM
    • Posts 151

    Hi,

    thanks for the answer but I haven't the file "aspnetdb.mdf " in my application directories...In addition,I use Sql Express Edition and I don't think is possible to attach my database file ...

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

    02-05-2007, 11:25 AM
    • Member
      106 point Member
    • raikkonen
    • Member since 09-29-2006, 9:43 AM
    • Posts 151

    Hi,

    thanks for the answer but I haven't the file "aspnetdb.mdf " in my application directories...In addition,I use Sql Express Edition and I don't think is possible to attach my database file ...

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

    02-05-2007, 8:32 PM
    Answer
    raikkonen:

    Hi,

    thanks for the answer but I haven't the file "aspnetdb.mdf " in my application directories...In addition,I use Sql Express Edition and I don't think is possible to attach my database file ...

    What is your error message?

    The original error of this thread is not able to attach the aspnetdb.mdf file using SQL Express:

    [SqlException (0x80131904): An attempt to attach an auto-named database for file C:\WebSites\Test_TimeTracker\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.]

    So If you are using SQL Express as Membership Provider, there is aspnetdb.mdf file, please use the asp.net Administrative Tool to configure users and roles, this tool will create this file automatically.

    If your error message shows different .mdf file name, please make sure the file is already exists under App_Data folder and it is accessible. Please check your connection string as well, e.g.

    <connectionStrings>
     <add name="aspnet_staterKits_Test_TimeTracker" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
     <remove name="LocalSqlServer"/>
     <add name="LocalSqlServer"connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"/>
    </connectionStrings>


     

    Zhao Ji Ma
    Sincerely,
    Microsoft Online Community Support

    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: An attempt to attach an auto-named database for file ... failed

    02-07-2007, 7:18 AM
    • Member
      106 point Member
    • raikkonen
    • Member since 09-29-2006, 9:43 AM
    • Posts 151
    Ok,thanks for your answers...I finally copy and paste the same database.mdf from my usb flash and it worked...so a good thing to do anytime is to backup always your application...Stick out tongue
  • Help attaching databases

    05-17-2007, 2:55 PM
    • Member
      69 point Member
    • abbadum
    • Member since 08-25-2006, 7:41 AM
    • Posts 15

    I need help attaching databases. I tried to use the attach string provided by my host and it doesn't work. I don't know what to do.

    This is my string:

    <add name="CLASSIFIEDSDB" connectionString="Data Source=.\SQLExpress;Integrated Security=True;Database=banana.qsh.es_ff7d004e-b930-40da-8e7a-dab56782dd2f;AttachDBFilename=|DataDirectory|CLASSIFIEDSDB.mdf;User Instance=True" providerName="System.Data.SqlClient"/>   
            <remove name="LocalSqlServer"/>
           
    <add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=SSPI;Database=banana.qsh.es_ca9a7de8-492f-47c5-bbc6-e2ad4eb27a40;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>

    </connectionStrings>

    The host is http://banana.qsh.eu 

     

    Should I keep the ldf files or they are created automatically when I tried to run the page for the first time?

     

  • Re: Help attaching databases

    05-17-2007, 2:56 PM
    • Member
      69 point Member
    • abbadum
    • Member since 08-25-2006, 7:41 AM
    • Posts 15

    If you can help me, please write directly to my email at ajarncarlos@gmail.com

    Thanks 

Page 1 of 2 (24 items) 1 2 Next >