What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 33247 |  Welcome, Guest!   Register  Login
Home > Articles > Error and Resolution > Troubleshoot Error: An attempt to attach an auto-named database for file <C:\database file path> failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Troubleshoot Error: An attempt to attach an auto-named database for file <C:\database file path> failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

1 vote(s)
Rating: 5 out of 5
Article posted by Abhisek on 6/2/2010 | Views: 17485 | Category: Error and Resolution | Level: Beginner red flag


This article tries to troubleshoot the error:
An attempt to attach an auto-named database for file <C:\database file path> failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

This article tells the step by step procedure to handle this type of error.

Introduction


This article tries to troubleshoot the error: 
An attempt to attach an auto-named database for file <C:\database file path> failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

You may get the error message similar to the following picture,



I have seen many articles stating the steps to resolve this issue. But when I face the problem for the first time, I get confused. Finally I resolve the problem after visiting one of such articles. But that article just gives the instructions, not the steps. So I decided to write this article with the step by step procedure to resolve the error.

There are several reasons for the above error. The last part of the error message - "A database with the same name exists, or specified file cannot be Opened, or it is located on UNC share" has nothing to do with. For the beginners it is a confusing error.

The problem manly occurs when we use the auto attach feature in Express editions of SQL Server. It is due to the fact that by default ASP.NET uses the default ASPNET account and the SQL Server does not allow it to access the database file.  

N.B:- Here I am using IIS7 as the server, Windows 7 as the OS and MS SQL Server Express 2005. Here I am assuming that you know the procedure how to add an ASP.NET application to the IIS server, change the security property and some basic functionality and features of the IIS server. This article only provide the steps to resolve the stated error. If your application is not configured properly with the IIS server then you might not be able to resolve the issue. So first make sure that you have configured your application correctly in the IIS.

The Procedure

Please follow the following 3 simple steps to resolve the above issue correctly.

Step 1:


First check your database connection and the connection string in the web.config file. The web.config file may look like the following,
<connectionStrings>
   <add name="ConnectionString" connectionString="Data                 Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Retinaa.mdf;Persist Security   Info=True;Integrated Security=SSPI;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
If your connection string is different then change it accordingly. User Instance=True will work only if your SQL Server 2005 Express is using Windows Authentication mode. It will fail if you are using mixed mode authentication

       To change the mode select the computer name in the SQL Server Management Studio, right click and select 'Properties'. Select 'Security' node to view/change the authentication mode.

Step 2:

     
       Now open the IIS console and locate your web application. Select the Authentication feature in the "Feature View" window.


       Then in the authentication window select "Anonymous User" and click on Edit. Give a valid account information by checking "Specific User" or you can check the "Application Pool identity".  



Step 3:


     Then select "ASP.NET Impersonate" and click Edit. In the dialog box check "Specific User" and click on "Set". Then give a valid windows account user name and password and click on OK. 



       Now you are almost done. Before browsing your application make sure that your web.config file contains the "identity impersonate" tag. You can also write the code directly in the web.config file in the <system.web> section. 
<identity impersonate="true" password="ap()@ru" userName="abhisek" />
        
Identity Impersonate property is used to control the identity under which code will be executed. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account. So the server is unable to find your database file. Hence you have to make use of Identity Impersonate property and give a valid account information as above. 

I hope this article will help you resolving the issue correctly. You can also search for other reasons in the web.

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:0 year(s)
Home page:
Member since:Sunday, October 11, 2009
Level:Bronze
Status: [Member]
Biography:Thanks and Regards
Abhisek Panda
Go Green And Save Your Future
>> Write Response - Respond to this post and get points
Related Posts

Many times we came across in debugging legacy applications built on ASP and COM. Debugging of legacy applications are error prone and complex.

When we work on a Macro enabled excel file with digital certificate, most of us faced the issue - “There was a problem with the digital certificate. The VBA project could not be signed. The signature will be discarded”. Today we will look a little deeper into the issue.

I always Blog about the Errors i got that are no Common, but i realised that few people might know about my Bloggs, so i decided to write an Article based on the Error and Solution from uncommon errors in the Programming World.

Errors And Resolution encountered by Programmers in their daily life

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 9:43:07 AM