none
An attempt to attach an auto-named database ....\aspnetdb.mdf failed

    Question

  • I've installed VWD 2005(Beta 2) and MS SQL Express and also followed the aspnet tour at http://beta.asp.net/guidedtour2. After trying new webcontrol (login control) and trying to execute the page, I've got an error such as below:

    An attempt to attach an auto-named database for file c:\inetpub\wwwroot\Demo\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.


    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file c:\inetpub\wwwroot\Demo\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.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:

    [SqlException (0x80131904): An attempt to attach an auto-named database for file c:\inetpub\wwwroot\Demo\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) +239 System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved) +815 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +80 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42 System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78 System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +161 System.Web.UI.WebControls.Login.AttemptLogin() +94 System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +134 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670
     

     


    can anyone help me to solve the problem... thanks

    Friday, October 14, 2005 8:09 AM

Answers

All replies

  • Please take a look at the following post:

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=98346 

    and see if the explanation there helps you to solve the problem.

    Regards,
    Boris.
    Friday, October 14, 2005 9:45 PM
  • But it's impossible to find the right solution in the forum. A lot of developers with the same problem and no real successful answer. The problem is not only in the beta products, it's still in the release version. In my case I took a web project working fine from one PC to another, copy the files change all relevant path entries and nothing goes anymore with the database files. Even not when trying to run the files on a SQL 2005 Developer Server.

    Trying over a weekend and still no solution (even after new installation of the SQL servers).

    Best regards,

    Eckmar  

    Monday, January 23, 2006 2:14 PM
  • What configuration do you have for aspnetdb.mdf in properties? You must set Copy to output: Copy if newer or Copy always. I recommended Copy if newer.

    Regards

    Monday, February 13, 2006 11:30 AM
  • I recently encountered this when I tried to add role management to a successfully operating user db. I had a connectionstring with a db name specified. Why should it need to autoname, or attempt to auto-attach? It must not be using the connectionstring I specified for the user db. I looked at the web config and the role manager entry was as follows;

    <roleManager enabled="true" />

    I modified it to be the following:

       <roleManager enabled="true" defaultProvider="SqlRoleProvider">
          <providers>
            <clear/>
            <add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="securityDB" />       
          </providers>
        </roleManager>.

    where securityDB was the connectionstring I was using for my DB. Made it work like a charm.

    Hope this helps.
    Monday, March 13, 2006 7:52 PM
  • Did you create this using Visual Web Developer Express? or Full Visual Studio 2005?

    I tried this in Express and it couldn't connect to my DB?

    Wednesday, March 15, 2006 3:27 AM
  • Here is a solution that I came up with...seeing as how most of the hosting solutions are shared IP, the SQLExpress will not be usable...therefore, you will have to create an SQL DB on your server...connect to it using the aspnet reqsql.exe to attach it to your app...write the connection string...set up the roles, users, etc with the aspnet configuration...and it works!!!

    I would venture to say that the SQLExpress is only for Local Intranets, and web developer machines.

    Saturday, March 18, 2006 3:09 AM
  • i had this same error, but it was due to me having an extra ODBC datasource (created by VISIO 2003) i believe. Fixed by; Goto Control Panel> admin tools> Datasources> File DSN tab then i deleted the overlapping datasource after 3 days of misery.
    Thursday, April 20, 2006 5:30 PM
  • Here is Permanent Solution of this Problem:

    Point 1:
    Make sure U have Database.mdf file under app_data directory if you are using |DataDirectory| in the Connection String.

    Point 2:
    string connstring = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";

    I hope this will solve your Problem.

    ShriannD
    Uni of Houston
    • Proposed as answer by ShrinanD Vyas Thursday, May 27, 2010 6:32 PM
    Friday, April 21, 2006 3:18 PM
  • In my case I had made a copy of a website, and both the old and new gave me that error on the development server for Visual Studio2005, perhaps because I made changes to the database.  By renaming the database in each instance, and making sure the connection string (in web.config) pointed to the correct website and file I seemed to have solved the problem.rookie
    Sunday, June 25, 2006 12:57 AM
  • I had the same problem with my website freehosting1.net
    What i did to resolve it was just to add the database property and delete the log file.
    But anyway sqlserver has alot of problems with error messages, like in this case it doenst give you specific information on what you should do to resolve it.
    Wednesday, September 20, 2006 10:45 PM
  •  mfauziii wrote:

    I've installed VWD 2005(Beta 2) and MS SQL Express and also followed the aspnet tour at http://beta.asp.net/guidedtour2. After trying new webcontrol (login control) and trying to execute the page, I've got an error such as below:

    An attempt to attach an auto-named database for file c:\inetpub\wwwroot\Demo\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.


    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file c:\inetpub\wwwroot\Demo\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.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:

    [SqlException (0x80131904): An attempt to attach an auto-named database for file c:\inetpub\wwwroot\Demo\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) +239 System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved) +815 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +80 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42 System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78 System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +161 System.Web.UI.WebControls.Login.AttemptLogin() +94 System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +134 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5670
     

     


    can anyone help me to solve the problem... thanks

    Monday, November 13, 2006 6:47 PM
  • I received the same error while doing a tutorial.  I had created my website under my user account located at C:\Documents and Settings\<your user account>\My Documents\Visual Studio 2005.  This apparently caused a permissions error that I wasn't aware of.  I moved the mdf and ldf file to the root c: and added "Everyone" to the permissions for the files.  Then I modifed the web.config file connection string to hard code the path to the file as below.  That got around the problem.  That's not a long term solution but it allowed me to continue on with the tutorial.

    <connectionStrings>

    <add name="NORTHWNDConnectionString"

    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=c:\NORTHWND.MDF;Integrated Security=True" providerName="System.Data.SqlClient" />

    </connectionStrings>

    Thursday, December 28, 2006 6:27 PM
  • I had exactly the same error when setting up a new database for logging. The problem was solved when I discovered the file permissions for both the mdf and ldf were incorrect. To ensure that ASP.NET can access these files from the App_Data folder you will need to set to Inherit from parent the permission entries that apply to child objects as seen in the Advanced file security settings.

    And a couple of other things to be aware of..
    1. If you attach the mdf file to an instance of SQLExpress in either Visual Studio or SQL Server Management Studio it will wipe out the Inherit from parent switch.
    2. SQLExpress cannot be run in more than one process at a time. So your web application is still active and holds onto a connection (and this is what the Enterprise Library Logging Application Block does) then you'll not be able to open the mdf anywhere else. Of course the reverse is true also. It took me an age to spot this and its so easy to fall into the trap!




    Tuesday, January 30, 2007 1:54 AM
  • It seems that the only kind of connection allowed for an database stored in App_Data is USER_INSTANCE=TRUE.  Once I moved the file to c:\myfolder\ , access could be as a server or a user instance. 
    Wednesday, April 18, 2007 1:58 AM
  • Thanks Dan, your workaround worked for me!

     

    Wednesday, May 23, 2007 4:59 PM
  • First Issue I had was with the ASPNETDB file that is created with VWD2005 EX ED when you create custom logins.

    NOTE: I run from a local Intranet with IIS running on a local server, not sure how to execute with a hosted server, you would have to get ahold of an administrator.

     

    I started off with the message that :

    [SqlException (0x80131904): Cannot open user default database. Login failed.
    Login failed for user 'xxx\ASPNET'.]

     

    The Fix for this was the follwing:

     

    The mdf file that is created when you setup user authentication for your project resides in the App_Data directory of your application tree.  Apparently by default the File level permission are set to not inherit and only provides Read/Write access to the user account that setup the application.  All I did was change the file security to inherit from parent and ensure the parent included read/write for the ASPNET account and it worked.

     

    How to:

    1. Using Windows Explorer, browse to the directory where your application resides.  Under that should be a directory called App_Data. 

    2. Right click the App_Data directory and then Select Security. 

    3. Click the Add button and add the ASPNET user to the list.

    4.  With the ASPNET user selected, make sure the Modify permission is checked (This will automatically enable the other permissions with the exception of Full.)  You may want to consider the security implications of providing the ASPNET account with full modify permission, but discuss this with the administrator.  At a mimimum the ASPNET account must have read & write.

    5.  Click OK to save and apply your changes.

    6.  Open the APP_DATA directory and select both the ASPNETDB and ASPNETDB_log files. 

    7.  Right click to view properties of both files.

    8.  Select the Security tab and verify that the Inherite permission for parent check is on.

    9.  Click OK to save and apply your changes.

    That should do the trick. When publishing to the web server, it may be necessary to add the IUSR account to the top level of your application, but I wouldn't think so.

     

    Second Issue I ran into was with the actual database I built to hold data, it returned the follwing error once I got past the login database above and tried to access a web page that held and instance   of it.

    A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

     

    My Fix was the following:

    Kept database in APP_Data Folder made sure that the inheritents from its parents were checked, I then changed the connection string in the web.config file from

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

    to this

    <add name="flatDCInvConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\App_Data\database_name.mdf;Integrated Security=True;User Instance=True"
       providerName="System.Data.SqlClient" />
     </connectionStrings>
     <system.web>

     

    Once this change was made everything works fine as it should.  Only Problem is that I am not sure this database is now running from SQL server?

     

    Hope this helps everyone else who was frustrated hunting for answers in these forums.

    Wednesday, June 20, 2007 9:04 PM
  • I have the problem as follows:

    1- I design web site on computer A (with Visual Studio 2005 & SQL 2005)

           a. I can set security as roles, user name,... with this computer A.

           b. Meaning I can use a login components to login web site using this computer A.

    2- When I publish this web site into my main web server, I can't login anymore.

           a. Try to copy the file \\app_data\ASPNETDB.MDB from computer A to main server, but it can't allow to copy.

           b. Stop SQL server on both computer A & server, I can copy above file. Then start SQL server on main PC, but I can't do the login into web site of main server.

    Does anyone know how to solve this simple problem?

    Wednesday, June 27, 2007 8:00 PM
  • Me Myself & I,

     

    Please, Please help !!!

     

    I have struggled with club site starter kit now for over 3 weeks.

     

    I have followed instruction but have always encountered the same problem of cannot attach database.

     

    I am hosting my site www.karmannghiaclub.com with www.webhosting4life.com and have discussed the problem at length with them but I think you have the answer ?

     

    I am however a complete amateur and do need simple help, could you please advise me of my steps I have followed below;

     

    1. Attach DB

     

    - Should I have uploaded both ASPNET.mdf & club.mdf or just club.mdf

    - Should I delete original DB files from site

     

    2. Grant Access to file

     

    - No issue

     

    3. Connection String

     

    - Really struggling with this could you please provide an example, do not understand use of aspnet reqsql.exe

     

    Really appreciate your help, very frustrated,

     

    Thanks

     

    Roger.

    Friday, June 29, 2007 11:55 AM
  • I can't explain this error but it is a frustrating one.  My problem started when I remoted into my work PC from my home PC.  Everything worked fine and then I started getting the message outlined by the original poster.  I was unable to do any role management within my site.

     

    there are many solutions that work for others but did not work for me.  I resolved the problem by going into the machine file located at:

     

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.xml

     

    I changed the name of the database in this default setting to aspnetdb2.mdf and all worked fine.  I still don't know how to get this to work with the default name (aspnetdb.mdf) and I'm done trying to figure it out for now.  I guess no more working from home until I get this one resolved permanently.

     

    <connectionStrings>

    <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb2.mdf;User Instance=true" providerName="System.Data.SqlClient" />

    </connectionStrings>

     

     

     

    Friday, July 06, 2007 1:27 PM
  • Did you finally get an answer for this?

     

     

    Tuesday, August 21, 2007 6:45 AM
  • I had the same error. It was due to the fact that I had accidentally moved my App-data folder to App_Code folder. asp.net /visual studio created another app_data folder in the application root. the were two aspnet.db.mdf databases in the application.hence it trying to  auto-attach a second aspnetdb.mdf file. I just deleted the new one and copied back the old one to the application root. Now it is working fine.

     

     

     

    Monday, December 03, 2007 1:48 PM
  •  

    I kid you guys not, this is thee most ANNOYING THING EVER!!!!, i get the exact same error. HOW ON EARTH do u develope a data driven application (SQL Server) and distribute it, imagine selling your app to a client, and they call ur err my software didnt work.

     

    IF ANYONE HAS GOT A SOLUTION PLEASE ENLIGHTEN US NOVICE DEVELOPERS.

    Saturday, February 16, 2008 9:35 PM
  • The post by Eric, BT Development on 20 Jun 2007 is the answer to this problem. I've worked on this very frustrating issue for sometime and by applying the steps outlined by Eric with one addition the problem is solved.

     

    Please don't post whines as responses to this issue on the message board, the posts should be only technical information and answers not pouting sessions, it really is rude and takes up space when people are looking for answers and every other post in the board is "I hate this, this sucks". Also, read the posts that outline the answers rather than post whines that the answer wasn't given, Eric had posted the answer and with a little self-discovery you would have found the one missing element, and three people have since posted "Why hasn't anyone solved this for me yet?" - you are only hurting yourselves (and the rest of us) when you clutter message boards with these types of posts, it makes answering the problem and reading/looking for the answers more difficult when you have to sift through these kinds of posts.

     

    What's giving the problem: the problem has to do with IIS ASPNET and IUSER permissions on the database, by giving the folder in which the databases are located Modify and Read Write permissions for ASPNET and IUSER respectively, as Eric outlined how to do that and posted earlier, you have to right-click on the Database and Log File within that folder, and then go into the Security tab, click Advanced, and in the Advanced section put a check mark on the Inherent from Parent directory setting, click Apply and OK - this should set the ASPNET and IUSER permissions correctly for both database files and now make the database accessible for IIS.

     

    The other issue that you'll get is that the database cannot be opened error message because a file with that name already exists - again as outlined by the second part of Eric's answer. The solution to this is to place the full path to the database in the web.config connection string, instead of the Attached Data | virtual path regularly used by VWD.

     

    The part that was missing or at least not fully stated in Eric's answer was that the Database file you are using should not be in the AppData folder used by VWD and the VWD built in test server, this conflicts with the IIS server. Instead copy the database to an outside folder, in Eric's case he moved it to the inetpub/wwwroot folder, in a previous post the author moved it to a C:/Database directory he created, and I moved it to another folder within my Microsoft Programs tree, as long as those permission settings are set on that folder and inherented by the database and log file (they both need to be together to work) as stated above then it will work when you launch the local IIS based website from VWD in debug/start mode from within VWD.

     

    At this point you'll be using IIS as the server and not the buggy and slow built-in Caspri (or whatever) test server from VWD. Again, after making a copy of the database files into this new folder and making sure you place the full path to the database file in the web.config connection string (and all the permissions set correctly) is what will make the site run in IIS rather than the built in VWD server for testing and debuging without the damn login errors.

     

    Note that this works with Windows XP Pro SP 2 and all the updates and IIS 5.1 that comes from the Windows XP CD rom. Using VWD Express Edition 2005, SQL Server 2005 Express Edition (both with service pack 1, latest updates), and SQL Management Studio Express, though it is not used in this case its a good tool for opening and manipulating the Databases and SQL Server.

     

    I also used the SQL configuation tool to Enable TCP/IP, NamePipes, and SQL Browsing connections and services - I did this from a previous attempt to fix this which didn't fix it but after applying the above fixes and leaving these settings enabled this fixed the issue.

     

    Knowing exactly what's going on as I've explained above will help you fix the issue if you have other settings and are using another machine set up, like Vista for instance, the settings are different but the root of the problem is the same. You just have to follow through and fix it. Also, the downloads I'm using are free and easy to get/install so if you have anohter set up, you can switch to this set up and have it work - the only difference would be the OS you are using, but that should not be too different from XP Pro.

    Saturday, April 05, 2008 2:53 AM
  •  Mr. A, Mohamed imtiyaz wrote:

     

    I kid you guys not, this is thee most ANNOYING THING EVER!!!!, i get the exact same error. HOW ON EARTH do u develope a data driven application (SQL Server) and distribute it, imagine selling your app to a client, and they call ur err my software didnt work.

     

    IF ANYONE HAS GOT A SOLUTION PLEASE ENLIGHTEN US NOVICE DEVELOPERS.

    I'm sorry, but I have to wholeheartedly agree with this post. I just wasted 3 days trying to get this to work, and it turns out the solution was to prepend "Initial Catalog=uniquenamehere;" to the connection string that Visual Studio generated. That's right, VS generates a connection string that doesn't work by default. Awesome.

     

    The final connection string section in Web.Config looks like this:

    Code Snippet

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

    </connectionStrings>

     

     

    ...where "uniquenamehere" is some name for your project.

     

    As someone in the field of computer science, it is astounding to me that such a high-profile commercial product would have such glaring errors in its final release. But then again, this is MSSQL, afterall...

     

    For the record, not one single error message given to me during the course of trying to fix this was relevant to the actual problem. Upon first receiving "An attempt to attached an auto-named database..." I looked online for every suggestion I could find: use an absolute path to the MDF, reorder TCP/IP and named pipes in the server configuration, disable/enable UserInstance (depending on where you looked), change security settings, reconfigure authentication, give specific login credentials.

     

    None of these worked. All of these led to different vague/ambiguous error messages, which led to another problem which required a solution which led back to the original error message... an endless loop of problems, completely unrelated to what was actually wrong.

     

    Also, posts about setting correct permissions on the App_Data folder are deceptive, as they imply the default permissions were not sufficient for SQL Express (in fact, they are). The whole point of this VS environment is that you can develop a web application and plop it right onto an IIS/SQLExpress setup and have it work. This makes the applications more portable (within IIS, of course) and secure. Of course, everything configuration-related has been obfuscated enough to make it several orders of magnitude more difficult than it has to be.

     

    Sigh...

    • Proposed as answer by EvilDr Wednesday, January 13, 2010 10:27 AM
    Friday, May 02, 2008 2:34 AM
  • It seems there are several problems that cause this error message. In my case, for some reason, changing the link to the database from the exact location to  "AttachDbFilename=|DataDirectory|\Database.mdf;" did the trick (where Database.mdf is the name of my database). How's this for a simple solution to three hours of angst!
    Thursday, July 17, 2008 9:31 PM
  • "It seems that the only kind of connection allowed for an database stored in App_Data is USER_INSTANCE=TRUE.  Once I moved the file to c:\myfolder\ , access could be as a server or a user instance. "
    Mp5k

    Thanks Mp5k that has been driving me crazy for about a week now. Every time I try to make a multi-user data base following a tutorial I am trying to get through, once I use the test app I have never been able to, in the c# express project, edit the database again or access it at all. Moved it from my desktop projects folder to c:\projects and everything works fine again and can access it.

    Now if i could just figure out when i run my little two table app why my ID column Identy that should be increamenting 1 starting at 1 shows as -1 -2 -3 -4 untill save
    and after closing down and restarting app then goes to the right number 1 2 3 4 ,,, or even entering new rows that any new entry theID shows as -1, -2 ,-3 again but after save and restart of the app it is the correct continuing idenity number as in this cause would be 5, 6, 7. very strange stuff

    Zerz
    Monday, September 08, 2008 5:20 AM
  •  

    System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);

    System.Configuration.ConnectionStringSettings connString;

    connString = config.ConnectionStrings.ConnectionStrings[0];

    SqlConnection conn = new SqlConnection(connString.ConnectionString);

     

    will fail if other connections to the database exist in the .aspx.

     

    either move the .mdf to your App_data,

    or

    hard code the connection string to read identically to your web config.

    SqlConnection conn = new SqlConnection("<<connections string here>>");

     

    Not satisfying, but it will get you on your way.

    Wednesday, September 17, 2008 7:52 PM
  • Do not attach the database file at the same time with SQL Server Management Studio Express as you can't attach the same database file to twice to two different SQL Server (Express) instances.

     

    Friday, October 17, 2008 4:08 AM
  • Luke,

     

    Your solution worked for me.  All I had to do was add the Initial Catalog to the connection string and it worked fine.  What's interesting is that this behavior only occurred when I used the ConnectionStrings section of web.config.  If I put the connection string sans Initial Catalog in a string variable within the page I received no exception.

     

    Thanks a million.

     

    Monday, October 27, 2008 3:30 AM
  •  

    I really frustrated with this error for more than two days.I tried all the resolutions posted on the net for this error,but no luck. First i really got confused, why its looking for aspnetdb.mdf which is not the actual mdf file name for the sqlserver instance/express that is installed on my machine.

     

    Finally, i debug the application.Some how i got the solution.This error occurs when you retrieve the connection string from the web.config using index.Initially i tried below.

     

    ConfigurationManager.ConnectionStrings[0].ConnectionString.ToString()

     

    When i tried above, i got the above error.After removing the index and accessing the connection string with name its worked for me.I just changed the above line like below.

     

    ConfigurationManager.ConnectionStrings["MyConnectionString "].ConnectionString.ToString()

     

    Where MyConnectionString is the name of the key given to the connection string in the web.config file.

     

    This is how i resolved the error.But there may be some other reasons for getting error.I am nt sure about that.But try this option too.

    Monday, December 01, 2008 10:09 AM
  •  

    I really frustrated with this error for more than two days.I tried all the resolutions posted on the net for this error,but no luck. First i really got confused, why its looking for aspnetdb.mdf which is not the actual mdf file name for the sqlserver instance/express that is installed on my machine.

     

    Finally, i debug the application.Some how i got the solution.This error occurs when you retrieve the connection string from the web.config using index.Initially i tried below.

     

    ConfigurationManager.ConnectionStrings[0].ConnectionString.ToString()

     

    When i tried above, i got the above error.After removing the index and accessing the connection string with name its worked for me.I just changed the above line like below.

     

    ConfigurationManager.ConnectionStrings["MyConnectionString "].ConnectionString.ToString()

     

    Where MyConnectionString is the name of the key given to the connection string in the web.config file.

     

    This is how i resolved the error.But there may be some other reasons for getting error.I am nt sure about that.But try this option too.

    • Proposed as answer by Layi Thursday, October 15, 2009 1:36 PM
    Monday, December 01, 2008 10:09 AM
  • Hi

     

    Insted of

     

    Wrong Code

    -----------------------

     

    conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=App_data\ASPNETDB.MDF;Integrated Security=True;User Instance=True"

     

    The correct code

    -------------------------

     

    conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"

    Friday, December 05, 2008 9:39 AM
  • Can anyone help further? I've carefully reviewed all of the postings in this thread, with particular attention to Eric, Tech-Solutions, and Luke, however there is exactly no change in the behavior - I still get the same error. Here are my particulars:

     

    I'm using MS-Visual Studio 2008 on one Windows XP machine that DOES NOT currently have IIS server, I am only using the ASP.NET development server, and the app I'm creating works perfrctly when run from Visual Studio.

     

    I have a sperate WinXP machine with IIS and SQL Server Express 2008 installed. After building the web in VS, I publish the site to this seperate machine. When the app is run there, the failure occurs when trying to create an account. In WInXP, there's no Security tab when viewing files/folders in Windows Explorer, so I assume that applies only to Win2K3 server.  

     

    I've created a very simple "WebSite1" app and used the "Login" tools to add basic controls in design view to an .aspx document. 

     

    This project does not have a connectionString entry in web.config, there is a</connectionString> tag, but no <connectionString> tag.

     

    I carefully added to web.config the suggested connection string entry mentioned in the posts by the aforementioned people, but the same error still occurs. I also note that this connection string is statically defined on the IIS server side of things, under Properties->[ASP.NET tab]->Edit Configuration->[General tab].

     

    Any other suggestions? Did I miss something here?

    Saturday, December 06, 2008 7:07 PM
  • I Encountered a similar problem, but the solution approached was..... i was trying to access a .mdf file which was by mistake deleted by me. So, no such file which was being accessed exists. Hence the exception. And when i restored the file to the data directory.....it worked.

     

    Hope the solution helps!! coz it did me

    Wednesday, December 10, 2008 11:30 AM
  • I went to the files in inetpub\wwwroot\mysitename\app_data\aspnetdb.mdf as well as aspnetdb_log.ldf.  On each one, I just went to properties and then security tab.  I added the group Everyone and gave this full control.  Just stopped the web site and restarted and it is working fine.
    • Proposed as answer by Piyush Zarkar Saturday, January 09, 2010 4:29 PM
    Thursday, March 19, 2009 7:07 PM
  • It may happens when user instance of SQL server didnt detach db after last connection. Try next: Connect to .\sqlexpress SELECT * FROM sys.dm_os_child_instances Connect to user instance server using instance_pipe_name field value as server name. See owner_principal_name to define wich one. Delete db. And more. Never copy ldf file of user instance db. What a ____ happens with forum? New PHP team? System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder(); builder.ConnectionString = db.Connection.ConnectionString; DbCommand dbCommandDropDb = db.Connection.CreateCommand(); dbCommandDropDb.CommandText = String.Format("use master; drop database [{0}]", builder.AttachDBFilename); db.Connection.Open(); dbCommandDropDb.ExecuteNonQuery(); db.Connection.Close();
    Thursday, April 09, 2009 8:00 AM
  • I'm sorry, but I have to wholeheartedly agree with this post. I just wasted 3 days trying to get this to work, and it turns out the solution was to prepend "Initial Catalog=uniquenamehere;" to the connection string that Visual Studio generated. That's right, VS generates a connection string that doesn't work by default. Awesome.

     

    The final connection string section in Web.Config looks like this:

    Code Snippet

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

    </connectionStrings>

     

     

    ...where "uniquenamehere" is some name for your project.



    Luke, thanks for your solution, it works for my problem. It's just stupid the way that microsoft throws error messages without sense, if only the error message said "Your connection needs a initial catalog" I wouldn't spend 5 hours to solve the problem!

    Again thank you Luke!

     
    • Proposed as answer by Piyush Zarkar Saturday, January 09, 2010 4:29 PM
    Wednesday, August 05, 2009 9:07 AM
  • "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.mdf;Integrated Security=True;User Instance=True;"

    works ;) 
    Thursday, October 15, 2009 1:39 PM
  • THE SOLUTION IS HERE

    The solution is simple... just right click the App_Data folder in Windows Explorer, go to the Security tab, click the "Advanced" button, click "Change permissions", select the option to propagate changes to children objects and click "Apply".
    • Proposed as answer by alexhiggins732 Thursday, December 17, 2009 7:03 PM
    Sunday, November 15, 2009 1:53 AM
  • The SOLUTION



    This drove me nuts, then I gave up and attached the database to a remote sqlserver.

    A few days later I got the error " Could not find part of the path E:\ when calling IO.Directory.CreateDirectory("E:\somepath")

    I Finally fixed the can not find part of the path issue by giving the ASPNET and the Network Service accounts List Content permissions on the E:\ drive. That then got me thinking may that was reason SQLExpress database could not auto attack a few days earlier.

    Sure enough, I changed the connection string back to autoattach the local database and it loaded fine. I then change someother database that where originally auto attached back to being auto attached again and they all loaded fine.

    In my case, even though ASP.NET, IUSR, and the Network Service account had full permissions to the database folder and the database files, It still could not auto attach because it the accounts didn't have List Content rights on the drive itself.



    So the Fix
    1. Make sure that the ASPNET and Network Service account have List Contents Permissions to the Drive the database is on. <-- My problem
    2. Make sure that the ASPNET and Network Service account has Full permissions to the folder the database is in.
    3. Make sure that the ASPNET and Network Service account has full permission to the database and the log file.
    4. Make sure that the [Databasefile] in AttachDbFilename=[Databasefile] part of the connection string is pointing to an absolute path, not a relative one
    5. Depending on how sqlexpress is setup,you may need to set User Instance=True in your connection string to allow the ASPNET account to access the database without admin privileges.
    Did I miss anything?

    • Edited by alexhiggins732 Thursday, December 17, 2009 7:19 PM typo
    • Proposed as answer by alexhiggins732 Thursday, December 17, 2009 7:19 PM
    Thursday, December 17, 2009 7:18 PM
  •  That's right, VS generates a connection string that doesn't work by default. Awesome.

     

    Code Snippet

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

    </connectionStrings>

     

    ...where "uniquenamehere" is some name for your project.

    Fantastic post.  Yes it is rediculous to think you should have to change permissions for an application that should be able to be copied directly to the destination server.  I am using Visual Studio 2010 Beta 2 and this problem of it generating a faulty connection string is still evident!

    Prepending Initial Catalog=xxxxx works perfectly .  I substituted xxxx with HA (my database file name is HA.MDF) and it works beautifully.

    Thank you for sharing your wisdom.
    Wednesday, January 13, 2010 10:30 AM
  • I can vouch for this! 

    Here's the relevant part of my web.config:

     

    <connectionStrings>

    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />

    <add name="SE_ServicesConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SE_Services.mdf;AttachDbFilename=|DataDirectory|\SE_Services.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />

     <add name="SE_ServicesConnectionString1" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SE_Services.mdf;AttachDbFilename=|DataDirectory|\SE_Services.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" /> 

    <add connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" name="LocalSqlServer" providerName="System.Data.SqlClient" />

    </connectionStrings>

    After 2 days of trying various "solutions" this one worked for me! 

     

    Monday, April 26, 2010 11:27 AM
  • Hi..

    I am creating a windows application using vb.net, and i am facing the same error mentioned .. iv tried almost everything bt the exception still persists..  i also tried changing the connection string to the one as under : 

     

     

     

            Myconnection = New OleDb.OleDbConnection("PROVIDER=SQLOLEDB;Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Projects\WindowsApplication1\Databases\

    M_database.mdf;Database=M_database;Integrated Security=SSPI;User Instance=True")


    the exception does not occur with the code above, bt then the question is this, i i hve to run the same application on another system, then wouldnt the AttachDbFilename become hard coded and cause problems too??  is there a way for me to get the path of the database , as in , the path where its stored in the project ?? not the path pointed by DataDirectory..

    Please do hlep me out, cz the deadlines almost approaching.
    Thank you
    any help will be appreciated.  

     

     

    Tuesday, June 08, 2010 3:49 AM
  • This solution works for me too, hours of searching to find out that the problem is such an error in the final release....
    Tuesday, September 14, 2010 2:22 PM
  • Thanks EvilDr, setting the "Initial Catalog" works for me.

    Byes


    lucaszacutti
    Tuesday, November 23, 2010 3:29 PM
  • Yes , setting the "Initial Catalog=mydbname" work for me too.

    Now is all clear. When auto-attaching a databse , SQLEXPESS create an istance for the user and create the attached db. If you dont set the Initial Catalog SQLEXPRESS try to attach the new database to an existind db ( the one active at runtime)

    Thursday, December 02, 2010 3:22 PM
  • If you have two connection strings or any of them is not the works one.(May one connection you created by manual and the other one created by a datasource object)

    Then program can give such type error message.

    So, you should decrease connections to just one...

     

    Wednesday, December 08, 2010 9:56 AM
  • thanks alot .... ur answer helped me and its working

     

    Thursday, February 24, 2011 7:45 PM
  • -Visual Studio 2010

    - Add "Initial Catalog=myproject;" to connection string
    (note, replace "myproject" with anything

    - Delete the .ldf file
    (this was what held me up.  Even if you do the above, the .ldf file seems to need deleting)

    Monday, March 28, 2011 9:00 PM
  • Thanks EvilDr
    Monday, July 04, 2011 10:15 PM
  • I received the access denied error when I tried using the ASPNETDB.MDF file in my ASP.NET app in VS2008 after I've attached it to my SQLEXPRESS server in SQL Server Management Studio Express with the purpose of editing it.

    This solved my problem:

    http://blogs.msdn.com/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

    Wednesday, July 13, 2011 9:03 PM
  • I'm having this error too using Visual Studio 2010 and SQL-server 2008 R2 (named instance) creating a Windows forms application.

    I tried the initial catalog solution but it didn't worked out.

     

    For some reason VS keeps looking at the old location of the DB (the bin\debug folder of the console testapplication), even when I replaced, deleted and recreated the database...

    I tried multiple connectionstrings, with the full db path, |Datadirectory| but it seems VS does not even reads out the App.config... It keeps just using the old path and I wonder why.

    Does anyone have a concrete solution please?

     

    Hoping on a resolution... thanks in advance

     


    Niko Verdoodt
    Sunday, July 31, 2011 2:26 PM
  • Hi thanks a lot  . .I solved my problem by your suggestion . . .
    Thursday, July 05, 2012 3:03 AM
  • Hey Boris,

    These links are broken.  Could you please fix them or post the article in its entirity?   Thanks!   :)

    Tim

    Saturday, September 01, 2012 5:30 AM
  • This is what finally helped me:
    http://support.microsoft.com/kb/2002980
    Friday, September 28, 2012 4:09 PM
  • This is broken link...

    Server Error in '/' Application.

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

    Requested URL: /error/error404.aspx

    Saturday, May 24, 2014 5:38 AM
  • This is broken link...Server Error in '/' Application.

    You expected a link posted nine years ago to be working? Isn't that a little optimistic?


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Saturday, May 24, 2014 8:15 AM