locked
CONNECTION STRING FROM WEB.CONFIG (VS 13) TRANSPLANTED TO APPSETTING.JSON (VS 19) RRS feed

  • Question

  • User-413595476 posted

    How can I transfer a connection string from a web,config file taken from a project produced in virtual studio 13 (highlighted in yellow below) to a AppSetting.json  file in a project produced in virtual studio 19?

    Errors: 

    Web

    HTTP Error 500.30 - ANCM In-Process Start Failure 

    output
    Exception thrown: 'System.FormatException' in Microsoft.Extensions.Configuration.FileExtensions.dll

     Included Below;
    -AppSettings.json
    -DAL.OutlineContext
    -Models.Level1
    _Models.Level2
    -Models.levelJoin1

    Programming Environment

    ___________________________________________________________________________________________________________________________

    {
      "Logging": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "AllowedHosts": "*",
      "ConnectionStrings": {
    
        "<add" "name=\"OutlineContext\"",
        "connectionString=\"Data Source=(LocalDb)\\v11.0;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\\Outline.mdf\"" "providerName=\"System.Data.SqlClient\"",
        "/>"
    
        // "cs": "Server=(localdb)\\mssqllocaldb;Database=cs-3e24dc9b-e3b5-4a06-b629-edeeed78359d;Trusted_Connection=True;MultipleActiveResultSets=true"
      }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    //
    using Outline.Models;
    using System.Data.Entity;
    using System.Data.Entity.ModelConfiguration.Conventions;
    
    
    namespace Outline.DAL
    {
        public class OutlineContext : DbContext
        {
            public OutlineContext() : base("OutlineContext") // The name of the connection string is passed in to the constructor.
            {
            }
            public DbSet<Level1> Level1s { get; set; }
            public DbSet<Level2> Level2s { get; set; }
            public DbSet<Join1> Join1s { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            }
        }
    }
    
      
    
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace Outline.Models
    {
        public class Level1
        {
            int Level1ID { get; set; }
    
            string LevelString1 { get; set; }
    
            public virtual ICollection<Join1> Join1s { get; set; }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace Outline.Models
    {
        public class Level2
        {
            int Leve21ID { get; set; }
    
            string Level2String1 { get; set; }
    
    
            public virtual ICollection<Join1> Join1s { get; set; }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace Outline.Models
    {
    
        public class Join1
        {
            public int JoinID { get; set; }
    
            public int Level1ID { get; set; }
    
            public int Leve21ID { get; set; }
    
            public virtual Level1 Level1  { get; set; }
    
            public virtual Level2 Level2 { get; set; }
        }
    }
    
    

    Thursday, June 20, 2019 12:41 AM

Answers

  • User1520731567 posted

    Hi colette95,

    colette95

    CONNECTION STRING FROM WEB.CONFIG (VS 13) TRANSPLANTED TO APPSETTING.JSON (VS 19)

    The configuration in appsetting.json is stored in name-value pairs. You can store it in Json, XML or INI file formats. 

    Like this article said.According to the highlight part,you could code in appsetting.json like:

    "ConnectionStrings": {
    "OutlineContext": "Data Source=(LocalDb)\\v11.0;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\\Outline.mdf\",
    "providerName":"System.Data.SqlClient"
    }

    And I suggest you could move to ASP.NET Core forum to get more help.

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 20, 2019 5:25 AM