p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4.5 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=710)
-   -   Chapter 16: Login tries to create database (http://p2p.wrox.com/showthread.php?t=90292)

rklein99 June 6th, 2013 05:57 PM

Chapter 16: Login tries to create database
 
Imaar,
When I try to execute the login or the create user functions, I get this error:

Cannot create file 'C:\BegASPNET\Site\App_Data\PlanetWrox.mdf' because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

It is trying to create 'C:\BegASPNET\Site\App_Data\PlanetWrox.mdf' and cannot because it already exists.

I set the web.Config as follows:

<connectionStrings>
<add name="PlanetWroxConnectionString1" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirec tory|\PlanetWrox.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="PlanetWroxEntities" connectionString="metadata=res://*/App_Code.PlanetWrox.csdl|res://*/App_Code.PlanetWrox.ssdl|res://*/App_Code.PlanetWrox.msl;provider=System.Data.SqlCl ient;provider connection string=&quot;data source=.;initial catalog=PlanetWrox;persist security info=True;user id=x2user;password=xedron02;MultipleActiveResultSe ts=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
.
.
<system.web>
<authentication mode="Forms" />
.
.
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvid er, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProv ider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="PlanetWroxConnectionString1" />
</providers>

I do not see a reason why it would try to create a database that exists.

Can you advise?

Thanks,

Rich Klein

Imar June 7th, 2013 02:31 AM

Hi Rich,

You seem to be using two different versions of SQL Server: Local DB for the PlanetWroxConnectionString1 and a unnamed instance (.) for the
PlanetWroxEntities. On the last instance, you attached a database and called it PlanetWrox. Is that database pointing to the same .MDF in the site's App_Data folder?

If so; this makes sense; you can't share the MDF file like this across two instances of SQL Server. Try pointing PlanetWroxConnectionString1 to the same instance of SQL server (or let PlanetWroxEntities point to LocalDB as well) and see if that fixes it.

Cheers,

Imar

rklein99 June 7th, 2013 08:43 AM

Thanks, Imaar. Both of those should be pointing to the same place, but I'll clean it up and try again and let you know.

Rich

rklein99 July 8th, 2013 05:25 PM

Just following up
 
Sorry, got busy at work. I'll post when I can work on this again.


All times are GMT -4. The time now is 02:32 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.