如何在简单的 Web 项目中连接到 .mdf(Microsoft SQL Server 数据库文件)? [英] How do I connect to an .mdf (Microsoft SQL Server Database File) in a simple web project?

查看:53
本文介绍了如何在简单的 Web 项目中连接到 .mdf(Microsoft SQL Server 数据库文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,在 VS 2008 中,我想连接到您可以通过右键单击自动生成的 App_Data 文件夹(.mdf数据库")来拥有的数据源.看起来很简单,一旦你知道怎么做.

Specifically, in VS 2008, I want to connect to a data source that you can have by right-clicking on the automatically-generated App_Data folder (an .mdf "database"). Seems easy, and it is once you know how.

推荐答案

这里是 MSDN 的答案:

So here's the answer from MSDN:

选择[e]添加新数据源"数据菜单.[并按照连接向导]

Choos[e] "Add New Data Source" from the Data menu.[And follow the connection wizard]

非常简单,只是我没有数据菜单.如果您没有数据"菜单,请执行以下操作:

Very easy, except that I have no Data menu. If you don't have a Data menu, do the following:

  • 点击工具>>连接到数据库...
  • 选择Microsoft SQL Server 数据库文件",采用默认数据提供程序,然后单击确定"
  • 在下一个屏幕上,浏览到您的数据库文件,该文件将位于您的 VS 解决方案文件夹结构中的某处.

测试连接.会好的.如果要将字符串添加到 web.config 中,请单击高级"按钮,然后复制数据源"行(在对话框底部),并将其粘贴到 web.config 中适当位置的连接字符串中文件.您必须添加AttachDbFilename"属性和值.示例:

Test the connection. It'll be good. If you want to add the string to the web.config, click the Advanced button, and copy the Data Source line (at the bottom of the dialog box), and paste it into a connection string in the appropriate place in the web.config file. You will have to add the "AttachDbFilename" attribute and value. Example:

来自高级面板的原始文本:

The raw text from the Advanced panel:

Data Source=.SQLEXPRESS;Integrated Security=True;Connect Timeout=30;User Instance=True

web.config 中的实际条目:

The actual entry in the web.config:

<add name="SomeDataBase" connectionString="Data Source=.SQLEXPRESS; 
AttachDbFilename=C:DevelopmentlahBlahApp_DataSomeDataFile.mdf;
Integrated Security=True; Connect Timeout=30; User Instance=True" />

这篇关于如何在简单的 Web 项目中连接到 .mdf(Microsoft SQL Server 数据库文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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