Setting EF Connection String in Azure Web App

后端 未结 4 1627
误落风尘
误落风尘 2020-12-30 04:10

We have an ASP .NET (MVC) app and are using Entity Framework 6 to connect to our databases. The DbContext is constructed in a standard way and it loads the connection string

4条回答
  •  天命终不由人
    2020-12-30 04:20

    Just recording my own experiences in addition to answers already recorded here

    This was my final connection string (on mutliple lines for clarity)

    metadata=res://*/Models.mBT.csdl|res://*/Models.mBT.ssdl|res://*/Models.mBT.msl;
    provider=System.Data.SqlClient;
    provider connection string="
      Data Source=tcp:myazureserver.database.windows.net,1433;
      Initial Catalog=databasename;
      User ID=z@myazureserver;
      Password=xyz"
    

    To convert from a "normal" connection string to one that is accepted by EF:

    • The connection string type in the application settings has to be "other" not "SQL Azure"
    • The connection string value automatically replaces anything published in web.config
    • The metadata name Models.mBT.csdl (and the other two) comes from this:

    Firstly, mBT is the name of my .edmx file

    With regards to the Model. bit, see the answer from @leqid here: MetadataException: Unable to load the specified metadata resource

    You can inspect your obj directory and see these three metadata files are in a subfolder called Models, so you need to prepend with Models.

提交回复
热议问题