0

My project so far consists of a simple, and empty, asp.net project solution using nothing besides what visual studio provides when you start a new project.

For the first time I am using migrations to help in my development. So far I have enable migrations fine and added an initial migration via the package manager console. The only change I have done is modifying my Web.config to look at a new data source like this:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=SYS-VIS-15\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-GiggHub-20160704033906.mdf;Initial Catalog=aspnet-GiggHub-20160704033906;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

Now, when I go to update my database by running 'update-database' in the package manager console I get the following error:

Directory lookup for the file "C:\Users\Admin\Source\Workspaces\GigHub\GiggHub\GiggHub\App_Data\aspnet-GiggHub-20160704033906.mdf" failed with the operating system error 5(Access is denied.). CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

I've checked all my permissions that I'm aware of, but can't see what I need to tick or untick to overcome this error. Does anyone know what to do?

The full file output is all follows:

Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.Data.SqlClient.SqlException (0x80131904): Directory lookup for the file "C:\Users\Admin\Source\Workspaces\GigHub\GiggHub\GiggHub\App_Data\aspnet-GiggHub-20160704033906.mdf" failed with the operating system error 5(Access is denied.).
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass1a.<CreateDatabaseFromScript>b__19(DbConnection conn)
   at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
   at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
   at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
   at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
   at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
ClientConnectionId:9b2f396d-dadf-4d0b-a334-1197e86beed1
Error Number:5133,State:1,Class:16
N0xus
  • 2,674
  • 12
  • 65
  • 126
  • Can you connect to your database using management studio ? – Hakunamatata Jul 05 '16 at 08:25
  • Provide some code to analyze, so that we can answer ur question. – Nirav Madariya Jul 05 '16 at 08:25
  • You say you only have SSMS installed, does that mean that you don't have the database engine installed? Also when you say `or on the database` do you mean the entity model in EF designer? – Barry O'Kane Jul 05 '16 at 08:26
  • I'm following this course: https://app.pluralsight.com/library/courses/full-stack-dot-net-developer-fundamentals/table-of-contents with SSMS I can connect to my database fine, but I've not created any databases inside of it myself. – N0xus Jul 05 '16 at 08:28
  • You said when you try to update the database you are getting an error, you have created database and tables in SSMS OR within VS only???? – Nirav Madariya Jul 05 '16 at 08:29
  • @NiravMadariya I've not written any code. All I've done so far is new project with MVC set up -> package management console 'enable-migrations' -> package management console -> 'add-migration InitialModel' -> PMC 'update-database' it's the last part where I'm getting the above error. – N0xus Jul 05 '16 at 08:30
  • Are you running Visual Studio as an administrator? – Simon Jul 05 '16 at 09:03

1 Answers1

0

In Visual Studio click on VIEW -> SQL Server Object Explorer -> Expand SQL Server node.If you don't see (localdb) in that list it means you don't have it installed.

To install local db have a look at this SO question

Community
  • 1
  • 1
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120