An attempt was made to connect the auto-named database for the <FILE> file. A database with the same name exists

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

I get an error when trying to add a user:

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

Error:

Failed to compile auto-name database for file C: \ Users \ Steven \ documents \ visual studio 2010 \ Projects \ MyApp \ MyApp.WebUI \ App_Data \ ASPNETDB.MDF. A database with the same name exists, or the specified file cannot be opened, or it is located on a UNC share.

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

<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 that the connection string is wrong, but I really have no idea.

+3
source share
4

?

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

, . , .

+1
  • , " "

  • | | "C:\inetpub\wwroot..."

.

+1

VisualStudio .

+1

Updating the application pool for the site in IIS Manager for ASP.NET v4.0 solved the problem for me.

0
source

Source: https://habr.com/ru/post/1792137/


All Articles