aspnet / JitBench

Repo for testing JIT stuff
Other
15 stars 24 forks source link

Deleting any existing DB file before initializing a new one #94

Closed fadimounir closed 5 years ago

fadimounir commented 5 years ago

Trying to create a new DB when one already exists throws an exception:

STDERROR: Unhandled Exception: System.AggregateException: One or more errors occurred. (Cannot create file 'C:\Users\Administrator\MusicStore.mdf' because it already exists. Change the file path or the file name, and retry the operation.
STDERROR: CREATE DATABASE failed. Some file names listed could not be created. Check related errors.) ---> System.Data.SqlClient.SqlException: Cannot create file 'C:\Users\Administrator\MusicStore.mdf' because it already exists. Change the file path or the file name, and retry the operation.
STDERROR: CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
STDERROR:    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
STDERROR:    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
STDERROR:    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
STDERROR:    at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
STDERROR:    at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
STDERROR:    at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
STDERROR:    at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
STDERROR: --- End of stack trace from previous location where exception was thrown ---
STDERROR:    at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
STDERROR:    at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQueryAsync(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
STDERROR:    at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQueryAsync(IEnumerable`1 migrationCommands, IRelationalConnection connection, CancellationToken cancellationToken)
STDERROR:    at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerDatabaseCreator.CreateAsync(CancellationToken cancellationToken)
STDERROR:    at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken)
STDERROR:    at MusicStore.Models.SampleData.InitializeMusicStoreDatabaseAsync(IServiceProvider serviceProvider, Boolean createUsers) in C:\J\w\perf_scenario---e0d43a79\bin\sandbox_logs\Scenarios\On\JitBench\K\src\MusicStore\Models\SampleData.cs:line 26
STDERROR:    --- End of inner exception stack trace ---
STDERROR:    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
STDERROR:    at System.Threading.Tasks.Task.Wait()
STDERROR:    at MusicStore.Startup.Configure(IApplicationBuilder app) in C:\J\w\perf_scenario---e0d43a79\bin\sandbox_logs\Scenarios\On\JitBench\K\src\MusicStore\Startup.cs:line 195
STDERROR:    at MusicStore.Startup.ConfigureProduction(IApplicationBuilder app) in C:\J\w\perf_scenario---e0d43a79\bin\sandbox_logs\Scenarios\On\JitBench\K\src\MusicStore\Startup.cs:line 166
STDERROR: --- End of stack trace from previous location where exception was thrown ---
STDERROR:    at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
STDERROR:    at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
STDERROR:    at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
STDERROR:    at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
STDERROR:    at MusicStore.Program.Main(String[] args) in C:\J\w\perf_scenario---e0d43a79\bin\sandbox_logs\Scenarios\On\JitBench\K\src\MusicStore\Program.cs:line 33
fadimounir commented 5 years ago

@rynowak could you please take a look at this small fix and merge it if it looks good?

rynowak commented 5 years ago

Looks good!