Visual Studion 2008 App_Data 默认值
是否可以将 App_Data 文件夹与 SQL Server 2005 结合使用?
当我尝试时,它指定了 Express,即使我已将“工具”>“选项”>“数据库”>“数据连接”更改为正确的服务器。我已在本地下载了 SQLEXPR32_x86_ENU.exe 版本 10.0.1600.22 文件,并进行了 7 次安装和卸载,但出现了各种不同的错误。我几乎放弃了 Express,并希望找到一种解决方法(如果存在)。
谢谢
丹尼斯·基思
Is it possible to use the App_Data folder in conjunction with SQL Server 2005?
When I try it specifies Express even though I have changed the Tools>Options>Database>Data Connections to the correct server. I have downloaded SQLEXPR32_x86_ENU.exe Version 10.0.1600.22 file locally and have gone through 7 installs and deinstalls with a variety of different errors. I pretty much given up on Express and would like to find a workaround if it exists.
Thanks
Dennis Keith
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 *.mdf 文件放入 App_Data 并将其作为用户实例数据库附加仅适用于 SQL Server Express,是的。
如果您想使用“真正的”SQL Server,您仍然可以将 *.mdf 和 *.ldf 文件放入 App_Data - 您只是无法将它们自动附加到您的 SQL Server 实例,您必须使用以下命令手动执行此操作SQL Server Management Studio(在 SSMS 的对象资源管理器中,转到“数据库”节点并右键单击,选择“附加...”,然后导航到 App_Data 文件夹并选择 *.mdf 文件)。
所以,是的,在某种程度上,Visual Studio 有一个 App_Data 文件夹,它对于 SQL Server Express(默认情况下随 Visual Studio 安装)最有意义。
马克
Putting a *.mdf file into your App_Data and attaching it as a user instance database works only with SQL Server Express, yes.
If you want to use "real" SQL Server, you can still put your *.mdf and *.ldf files into App_Data - you just can't automagically attach them to your SQL Server instance, you'll have to do this manually using SQL Server Management Studio (in the Object Explorer of your SSMS, go to the "Databases" node and right-click, pick "Attach...." and then navigate to your App_Data folder and pick the *.mdf file).
So yes, in a way, Visual Studio has a App_Data folder that makes most sense with SQL Server Express (which is being installed with Visual Studio by default).
Marc
您可以将 SQL Server 2005(或 2008)数据库与 Web 应用程序或网站项目一起使用。您可能可以将数据库文件(
.mdf
、.ldf
)放在App_Data
文件夹中(请记住您需要附加数据库1 直接连接到 SQL Server — 自动连接文件仅适用于 Express)。但您确实需要确保应用程序使用的数据连接设置为使用应用程序自己的
web.config
中定义的连接字符串。默认情况下,由于全局machine.config
2 设置成员资格的内容,成员资格提供程序默认为App_Data
中的 SQL Express 数据库提供者使用连接LocalSqlServer
在同一文件中设置为:其中
|DataDirectory|
将在运行时被应用程序根目录中的App_Data
替换。总结应用程序(web.config,VS 的数据连接在设计器之外不使用)需要:
.mdf
,其连接字符串使用“AttachDBFilename
”。.mdf
、.ldf
)可以访问。所有连接字符串都通过“数据源
”(用于设置服务器名称)和“初始目录
”来引用该数据库以设置数据库。 IIS 应用程序池的帐户需要能够访问 SQL Server。1 使用 SQL Management Studio 来执行此操作。 (感谢其他答案提醒我。)
2 请参阅
%SystemRoot%\\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
。这You can use a SQL Server 2005 (or 2008) database with a Web Application or Web Site project. You can probably have the database files (
.mdf
,.ldf
) in theApp_Data
folder (and remember you need to attach the database1 to SQL Server directly—the auto-connect file only works with Express).But you do need to ensure the data connections used by the application are set to use connection strings defined in the application's own
web.config
. By default things like the membership provider default to a SQL Express database inApp_Data
due to the contents of the globalmachine.config
2 setting the membership provider to use connectionLocalSqlServer
which is set in the same file to be:Where
|DataDirectory|
will be replaced at runtime byApp_Data
in the application root.Summary the application, (web.config, VS's data connections are not used outside the designer) needs to either:
.mdf
in the App_Data folder with a connection string using "AttachDBFilename
"..mdf
,.ldf
) in a location that the SQL Server user account can access. All the connection strings reference that database via "Data Source
" (to set server name) and "Initial Catalog
" to set the database. The account for the IIS application pool needs to be able to access SQL Server.1 Use SQL Management Studio to do this. (And thanks to the other answer for reminding me.)
2 See
%SystemRoot%\\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
. The