ASP.NET ConnectionString AttachDbFilename=|DataDirectory|

后端 未结 4 1426
醉酒成梦
醉酒成梦 2021-01-06 01:12

This is about ConnectionStrings / ASP.NET MVC with Visual Studio 2012 ultimate & SQL Server Express 2012.

Following up with this tutorial here: http://www.asp.ne

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 01:32

    after research/tests it turned out to be as follows:

    VS will look at the class name of the DataContext and will look to see if you have provided a connection string with the same name as the class name; for example:

    public class MovieDataContext : DbContext
    

    and

    if it manages to find a matching connection string it will create the DB based on the criteria you specified in the respective data string (to add the DB to the App_Data set the path of the DB to |DataDirectory| as shown in both connection strings mentioned in the question); if the name doesn't match or you didn't provide any connection string, VS will fall back to the default settings and will create the DB in the default location/settings (usually C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA).

    note neither the "Integrated Security" settings nor the "Initial Catalog" play any role with this (I was able to create the DB in the App_Data with both Integrated Security = True & Integrated Security = SSPI and with/without Initial Catalog).

    Hope this helps. Thanks for everyone that participated.

提交回复
热议问题