skip to Main Content

I got this error "Format of the initialization string does not conform to specification starting at index 0."
while migrating.

my connection string given in

appsettings.json

"ConnectionStrings": {
 "DefaultConnection": "Data Source=LAPTOP-P08F3TG1/ckary;Initial Catalog=Product;Integrated Security=True"
 },

ApplicationDbcontext.cs

 public class ApplicationDbContext:DbContext
    {
        public DbSet<Login> Logins { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("DefaultConnection");
        }

please help to findout my mistake

correct answer or format to solve my error

2

Answers


  1. Could you try this?

    "ConnectionStrings": {
     "DefaultConnection": "Data Source=LAPTOP-P08F3TG1ckary;Initial 
      Catalog=Product;Integrated Security=True"
     }
    
    Login or Signup to reply.
  2. Try:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                IConfigurationRoot configuration = new ConfigurationBuilder()
                    .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                    .AddJsonFile("appsettings.json")
                    .Build();
                optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"));
            }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search