L
L
lena_shevtsova2022-01-25 18:52:58
ASP.NET
lena_shevtsova, 2022-01-25 18:52:58

Why is there an error about the impossibility to create a database?

I'm not trying to create a database here, why does this error occur?
61f01c70d1818501889338.png

stacktrace

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) in System.Data.SqlClient.TdsParser.TryRun (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean & dataReady) in 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& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c.b__4_0(DbCommand t, DbCommandInterceptionContext `1 c) in System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) in System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) to System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass52_0.b__0(DbConnection conn) to System.Data.Entity.SqlServer.SqlProviderServices .<>c__DisplayClass60_0.b__0() in System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass2_0.b__0() in System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) in System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) to System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act) to System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) to System.Data.Entity .SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) to System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) to System.Data.Entity.Core .Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) in System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase() in System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) in System. Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) to System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) to System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext) to System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) to System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) to System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) in System.Data.Entity.Internal.InternalContext.<>c__DisplayClass66_0`1.b__0() in System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) in System.Data.Entity.Internal. InternalContext.PerformDatabaseInitialization() in System.Data.Entity.Internal.LazyInternalContext.<>c.b__58_0(InternalContext c) in System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) in System.Data.Entity. Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) to System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() to System.Data.Entity.Internal.InternalContext.Initialize() to System.Data.Entity.Internal.InternalContext. GetEntitySetAndBaseTypeForType(Type entityType) in System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() in System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() in System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() in ASP._Page_Views_Home__TabRent_cshtml.Execute() in C:\Users\elena\source\repos \elena3569\RealtyStore\realtyStore\Views\Home\_TabRent.cshtml: line 11 in System.Web.WebPages.WebPageBase.ExecutePageHierarchy() in System.Web.Mvc.WebViewPage.ExecutePageHierarchy() in System.Web.WebPages.WebPageBase. ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) to System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) to System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) to System .Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer,ViewEngineCollection viewEngineCollection) in System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName) in ASP._Page_Views_Home_Index_cshtml.Execute() in C:\Users\elena\source\repos\elena3569\RealtyStore\realtyStore\Views\ Home\Index.cshtml: line 44 in System.Web.WebPages.WebPageBase.ExecutePageHierarchy() in System.Web.Mvc.WebViewPage.ExecutePageHierarchy() in System.Web.WebPages.StartPage.RunPage() in System.Web.WebPages .StartPage.ExecutePageHierarchy() in System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) in System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) in System.Web .Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) to System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) in System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) in System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) in System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) in System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

realtucontext

public class RealtyContext : DbContext
    {
        public DbSet<Realty> Realties { get; set; }
        public DbSet<myUser> Users { get; set; }
        public DbSet<Sold> Sold { get; set; }
        public DbSet<Leased> Leased { get; set; }
        public DbSet<City> Cities { get; set; }
        public DbSet<ApplicationToRealtor> Apps { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<FavoriteRealties> FavoriteRealties { get; set; }
    }


the error started to appear after changing the connection string
while it was default, everything was fine,
added this line and started
<connectionStrings>
    <add name="RealtyStoreContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='|DataDirectory|\Realtystore.mdf';Integrated Security=True" providerName="System.Data.SqlClient" />
  
</connectionStrings>


and after adding this line, the error handler stopped working
<httpErrors errorMode="Custom">
           <error statusCode="404" subStatusCode="-1" path="/notfound" responseMode="ExecuteURL" />
     </httpErrors>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-01-25
@vabka

It is written - the file on the specified path already exists.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question