ASP.NET的ConnectionString AttachDbFilename = | DataDirectory目录| [英] ASP.NET ConnectionString AttachDbFilename=|DataDirectory|

查看:367
本文介绍了ASP.NET的ConnectionString AttachDbFilename = | DataDirectory目录|的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关的ConnectionStrings / ASP.NET MVC与Visual Studio 2012的最终和放大器; SQL Server的防爆preSS 2012。

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

跟进本教程此处的http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4我碰到一个问题就与这两个连接字符串在我的web.config:

Following up with this tutorial here: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4 I came across an issue with these two connection strings at 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>

该网站工作正常,但为什么在App_Data文件夹中创建的第一个数据库,而第二个是在C创建我不能fingure出来:\\ Program Files文件\\ Microsoft SQL Server的\\ MSSQL11.SQLEX $ P $干燥综合征\\ MSSQL \\ DATA?我认为,这两个将在APP_DATA创建,因为都使用这个属性:AttachDBFilename = | DataDirectory目录|

the website works fine but I couldn't fingure out why the first db is created in the App_Data folder while the second one is created in "C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA"?! I supposed that both will be created in App_data because both utilize this attribute: AttachDBFilename=|DataDirectory|!

请注意:本教程中提到,它应该是在App_Data&放大器;他们增加了屏幕截图,有说明它哉!

note: the tutorial mentions that it should be in the App_Data & they added a screenshot that shows it there indeed!

我一直在寻找一个答案,钻进SQL的同谋(我想用户实例可能是解决方案),但此未能达成一个答案:|

I have been looking for an answer and got into the complicity of SQL (I thought User Instances might be the solution) but couldn't reach an answer for this : |

(这可能阅读有关用户实例的 http://msdn.microsoft.com/en-us/library/bb264564(v = SQL.90)的.aspx

(this might be useful to read about User Instances http://msdn.microsoft.com/en-us/library/bb264564(v=sql.90).aspx)

任何想法是极大的AP preciated。先谢谢了。

Any ideas are greatly appreciated. Thanks in advance.

问候

推荐答案

在研究/测试中,它竟然是如下:

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

VS会看在DataContext的类名,并会看看如果您提供具有相同名称作为类名称的连接字符串;例如:

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

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

如果它设法找到匹配的连接字符串,它会根据你在相应的数据串指定的标准创建DB(添加数据库到App_Data文件设置数据库的路径| DataDirectory目录|如图都在问题中提到的连接字符串); 如果名称不匹配,或者您没有提供任何连接字符串,VS将回落到默认设置,并会在默认位置/设置(通常是C创建DB:\\ Program Files文件\\ Microsoft SQL Server的\\ MSSQL11.SQLEX $ p $干燥综合征\\ MSSQL \\ DATA)。

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).

请注意,无论是集成安全性的设置,也不是初始目录玩任何与此角色(我能在App_Data创建数据库同时安装了集成安全=真放大器;集成安全性= SSPI和有/无初始目录)。

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.

这篇关于ASP.NET的ConnectionString AttachDbFilename = | DataDirectory目录|的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆