• 1397/09/12

خطا در add migration :

سلام استاد

زمانی که add-migration initialdatabase را میزنم خطای زیر را میدهد:

 

Value cannot be null.
Parameter name: connectionString
---------

 

ApplicationDbContext.cs:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(_configuration["ApplicationDbContextConnection"]);
        }

-------

Startup.cs:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IConfigurationRoot>(provider => { return Configuration; });
            services.AddDbContext<ApplicationDbContext>(options =>
            {
                options.UseSqlServer(Configuration["App::ConnectionStrings:ApplicationDbContextConnection"]);

                services.AddDbContext<ApplicationDbContext>();
            });
        }

------

appsettings.json:

"ConnectionStrings": {
    "ApplicationDbContextConnection": "Data Source=.\\hooh;Initial Catalog=dbase;User Id=sa;Password=123;Trusted_Connection=True;MultipleActiveResultSets=true"
  }

 

ممنون میشوم راهنمایی کنید.

  • 1397/09/12
  • ساعت 10:49

متن کامل خطا را قرار دهید 


  • 1397/09/12
  • ساعت 10:50

 

add-migration initialdatabase
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)
   at EVS.WebApp.Startup.<>c__DisplayClass5_0.<ConfigureServices>b__1(DbContextOptionsBuilder options) in C:\Users\HooH\Desktop\EVS\EVS\EVS.WebApp\Startup.cs:line 46
   at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory[TContext](IServiceProvider applicationServiceProvider, Action`2 optionsAction)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes()
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextType(String name)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: connectionString

  • 1397/09/12
  • ساعت 10:51

میگه مشکل از رشته اتصال هست و نمیتونه پیدا کنه 

مطابق با پروژه من در دوره عمل کنید 


logo-samandehi