3

I have the ASPNETDB.MDF database in the App_Data folder of my project.

I'm getting an error when I try to add a user:

MembershipUser user = Membership.CreateUser(viewModel.Username, viewModel.Password, viewModel.Contact.Email,
                                            viewModel.SecurityQuestion, viewModel.SecurityAnswer, true, out createStatus);

The error is:

An attempt to attach an auto-named database for file C:\Users\Steven\documents\visual studio 2010\Projects\MyApp\MyApp.WebUI\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.

My web.config has this connection string and membership info:

<connectionStrings>
    <add name="ASPNETDB" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ASPNETDB" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ASPNETDB" applicationName="/" />
  </providers>
</profile>
<roleManager enabled="true">
  <providers>
    <clear />
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ASPNETDB" applicationName="/" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>

I have a feeling my connection string is wrong, but I really have no idea.

1

4 Answers 4

1

For starters will you please give this connection string a try?

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

I am also curious to know are you able to access the database at all from your application. From your error, I would assume no.

1
  • While directory permissions, create new user "network service" and configure permissions

  • Replace |Data directory| to "C:\inetpub\wwroot..."

It is successful.

1

Running VisualStudio as Administrator solves this problem during development.

0
0

Updating the application pool for the Site in IIS Manager to ASP.NET v4.0 solved the issue for me.

1
  • I doubt he's using IIS with the path of his project. Oct 21, 2012 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.