ASP.NET ConnectionString AttachDbFilename = | DataDirectory |

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

Following this guide, http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4 I ran into a problem with these two connection strings on my web.config:

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=(LocalDb)\v11.0;
                           Initial Catalog=aspnet-MvcMovie-users;
                           Integrated Security=SSPI;
                           AttachDBFilename=|DataDirectory|\aspnet-MvcMovie-users.mdf"
         providerName="System.Data.SqlClient" />

    <add name="MovieDBContext" 
         connectionString="Data Source=(LocalDB)\v11.0;
                           AttachDbFilename=|DataDirectory|\Movies.mdf;
                           Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

the site is working fine, but I could not understand why the first db was created in the App_Data folder, and the second was created in "C: \ Program Files \ Microsoft SQL Server \ MSSQL11.SQLEXPRESS \ MSSQL \ DATA" ?! I assumed that both will be created in App_data because both use this attribute: AttachDBFilename = | DataDirectory |!

: , App_Data, , !

SQL ( , ), : |

( http://msdn.microsoft.com/en-us/library/bb264564(v=sql.90).aspx)

. .

+5
4

/ :

VS DataContext , , ; :

public class MovieDataContext : DbContext

<connectionStrings><add name="MovieDataContext" ...

, , ( App_Data, | DataDirectory |, , ); , - , VS / ( C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA).

: " ", " " ( App_Data = True Integrated Security = SSPI / ).

, . , .

+15

. , Integrated Security. SQLExpress Movies , MS SQL Server Management Studio.

. Integrated Security = True Integrated Security = SSPI

0

, AMT, . , .mdf .sdf.

, , , , DBContext OrConnectionString

public BlogsContext()
            : base("name=EFBlogs")
        {
        }

Then the application looks for the connection string named EFBlogs, if it cannot find the connection string, then it creates a database named EFBlogs, not BlogsContext

0
source

Hey. I notice the difference when adding the database and asks if you want it to be placed in the app_data folder, if you click yes, it will go to the app_data folder, and the full path name to mdf is also in the app_data folder, in which you are using file explorer.

0
source

All Articles