Setting the SQL connection string for ASP.NET Core web app in Azure

后端 未结 4 1399
庸人自扰
庸人自扰 2020-12-03 06:36

I have created a new ASP.NET Core web application in Visual Studio 2015. I\'ve also set up an Azure web app to pull in the app from GitHub and run it. This works fine, but I

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 07:17

    In RC2 I had to change how my connection strings were read to get them to work in Azure. In my case I had to ensure the Azure connection string was named "DefaultConnection", and accessed by:

    RC1:

    {
        "Data": {
            "DefaultConnection": {
                "ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=db;Trusted_Connection=True;"
            }
        }
    }
    

    Accessed by:

    var conn = Configuration["Data:DefaultConnection:ConnectionString"];
    

    RC2:

    {
      "Data": {
    
      },
      "ConnectionStrings": {
        "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=db;Trusted_Connection=True;"
      }
    }
    

    Accessed by:

    var conn = Configuration.GetConnectionString("DefaultConnection");
    

提交回复
热议问题