I am getting error:'Could not open new database' while creating EpiServer Web Site by using VS

Vote:
 

Hi,

I am getting below error when I select Empty template to create EpiServer Web Site by VS.

Also, no DB is created in App_Data. Only GeoLiteCity.dat file is created under this folder.

Please help.

Server Error in '/' Application.Could not open new database 'EPiServerDB_2767df9b'. CREATE DATABASE is aborted.

Cannot attach the file 'C:\EpiDemos\PML\PML\App_Data\EPiServerDB_2767df9b.mdf' as database 'EPiServerDB_2767df9b'.
File activation failure. The physical file name "C:\EpiDemos\PML\PML\App_Data\EPiServerDB_2767df9b_log.ldf" may be incorrect.
The log cannot be rebuilt when the primary file is read-only.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Could not open new database 'EPiServerDB_2767df9b'. CREATE DATABASE is aborted.
Cannot attach the file 'C:\EpiDemos\PML\PML\App_Data\EPiServerDB_2767df9b.mdf' as database 'EPiServerDB_2767df9b'.
File activation failure. The physical file name "C:\EpiDemos\PML\PML\App_Data\EPiServerDB_2767df9b_log.ldf" may be incorrect.
The log cannot be rebuilt when the primary file is read-only.

Source Error: 

[No relevant source lines]


Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\427d5686\520a12d0\App_global.asax.0.cs    Line: 0 

Stack Trace: 

[SqlException (0x80131904): Could not open new database 'EPiServerDB_2767df9b'. CREATE DATABASE is aborted.
Cannot attach the file 'C:\EpiDemos\PML\PML\App_Data\EPiServerDB_2767df9b.mdf' as database 'EPiServerDB_2767df9b'.
File activation failure. The physical file name "C:\EpiDemos\PML\PML\App_Data\EPiServerDB_2767df9b_log.ldf" may be incorrect.
The log cannot be rebuilt when the primary file is read-only.]
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +414
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +167
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +83
   System.Data.SqlClient.SqlConnection.Open() +96
   EPiServer.Data.Providers.ConnectionContext.b__0() +147
   EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute(Func`1 method) +1330
   EPiServer.Data.Providers.ConnectionContext.OpenConnection() +179
   EPiServer.Data.Providers.SqlDatabaseHandler.GetConnection(Boolean requireTransaction) +430
   EPiServer.Data.Providers.<>c__DisplayClass1`1.b__0() +66
   EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute(Func`1 method) +1333
   EPiServer.Data.Providers.SqlDatabaseHandler.Execute(Func`1 action) +214
   EPiServer.Data.Providers.SqlDatabaseHandler.Execute(Action action) +157
   EPiServer.Initialization.CmsDataInitialization.Initialize(InitializationEngine context) +259
   EPiServer.Framework.Initialization.<>c__DisplayClass5.b__4() +56
   EPiServer.Framework.Initialization.ModuleNode.Execute(Action a, String key) +73
   EPiServer.Framework.Initialization.ModuleNode.Initialize(InitializationEngine context) +141
   EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +445
   EPiServer.Framework.Initialization.InitializationEngine.Initialize(HostType hostType) +256
   EPiServer.Framework.Initialization.InitializationModule.Initialize(HostType hostType) +342
   EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +78
   EPiServer.Global..ctor() +83
   PML.EPiServerApplication..ctor() +42
   ASP.global_asax..ctor() in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\427d5686\520a12d0\App_global.asax.0.cs:0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +1136
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +128
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +18
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +260
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
#88625
Jul 21, 2014 11:55
Vote:
 

Most of the time when I get this problem, I take the mdf and ldf files and adds them to my local SQL database (SQL Express works).

Not the best solution but at least a workaround that works for me.

#88626
Jul 21, 2014 12:14
Vote:
 

Ensure your application App_data folder: C:\EpiDemos\PML\PML\App_Data\ has permissions so the database can be created. I normally add Everyone > all on a dev machine.

#88632
Jul 21, 2014 21:15
Vote:
 

Try rynning as admin in VS? Are you also trying to add the project to for instance TFS at the same time? That procedure can lock files to be read only as well.

#88634
Jul 22, 2014 10:42
Vote:
 

This issue may still occur if the user running the application, i.e. Visual studio doesn't have access to the app_data folder as David Knipe suggested. Ensure the user running the application has full access to the app_data folder by modifying the permissions.

Also, if this is a new project adding createDatabaseSchema="true" on the episerver.framework element may help unless you prefer updating the database manually by running the cmdlet 'Initialize-EPiDatabase' in the package manager console.

<episerver.framework createDatabaseSchema="true" updateDatabaseSchema="true">
...
</episerver.framework>
#174843
Edited, Feb 06, 2017 23:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.