We help IT Professionals succeed at work.

Deploying aspnetdb.mdf to production server

Medium Priority
Last Modified: 2011-09-21
Hi - I am trying to deploy a simple ASP.NET 2.0 application to a server. The application uses the roles and membership features so that I can make use of the builtin Logon controls. This works fine on my development machine. When I try to run it on my server, I manage to get my logon page, but when I try to logon I get the following error message....

Server Error in '/wms2' Application.
An attempt to attach an auto-named database for file D:\ftp\wms\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 have read through other forums discussing this error, but none seem to be relevant. I am not sure where to proceed from here. Do I need to install Visual Studio on my production server, or is there some sort of SQL Server Express registration required with .NET? I installed SQL Server Express after I deployed my app.
Watch Question

you can change the personalization provider to work with your preferred server rather than the built in express that stores the info in your app_data folder as a *.mdf

You should back up your site first because although it is possible to undo what i am about to describe using the same means, i haven't had much luck.

go to start > programs > microsoft visual studio 2005 > visual studio 2005 command prompt

once that opens type aspnet_regsql.exe and press enter

work your way through the wizard to associate the server you want to use with asp.net's personaliztion features like user logins, memberships, and profiles


Will this mean that there will be a single database for both environments? I really need to be able to have two independent databases as the production server is at another site. Sharing a database is not an option.  

I'm sorry but i'm not sure i understand what you mean

by default VS 2005 stores the personalization information in the ASPNETDB.MDF file in the App_Data folder.  if you want it to use your preferred database you can follow the steps above.  You can use sql express or whatever to handle your personalization features.  

what this means is that all of the data your application uses will be in one database instead of the database and the *.mdf file.

If you are having trouble migrating the *.mdf file to a remote server, i recommend following the steps above to tell vs 2005 to use it to handle the personalization options.  when you are ready to move it to production use the wizard again to point it to that server.

Hope this helps


I think it comes down to my lack of understanding of the MDF file and how it is managed/connected. Prior to this, I used an Access database to manage my user accounts and logons. I was expecting the the aspnetdb.mdf file to behave the same way (i.e. just copy it over to the production server and change any relevant connection strings). Am I correct? Or does the MDF file have to SQL Express installed, and you have to somehow tell your app which database to use?

I ran through the wizard (btw, I don't have VS2005 installed in production but aspnet_regsql.exe is in the the .NET Framework directory) and it failed due to permissions so this may be where my initial problem lies.

I will keep at it... I think I just need sleep :)


I got there finally.... but it is a work around for my original problem - not the solution. It appears that I SHOULD just be able to copy the ASPNETDB.MDF (and LDF) files to my app and they will be automatically attached to SQL Express. But it doesn't work.

To work around this, I had to manually attach to the aspnetdb.mdf file using SQL Express Manager. The default database name was set to the pathname on my development PC (NOT the actual path on my server) - anyway, that may be irrelevant. I renamed the database name to "MyDatabase".

In IIS, I went to my virtual directory, and loaded up the ASP.NET configuration properties, and replaced the connection string with the following....
Data Source=.\SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=MyDatabase

Back to the original problem, is the auto-attach failing because it is looking in the original database path (from my PC), not the new pathname on my server? I.e. it is looking at C:\Documents and Settings\trev\Local Settings....... instead of D:\www\www\App_data\aspnetdb.mdf ?

man your still working on this, what dedication, now you can finally get that sleep you spoke of three hours ago
PAQed with points refunded (500)

Community Support Moderator

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.