Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(3)

来源:互联网 发布:菜鸟网络联系电话 编辑:程序博客网 时间:2024/05/29 16:51

Browsing and Modifying Databases in Visual Studio
As an ASP.NET developer, you may have the responsibility of creating the database required for a web application. Alternatively, it may already exist, or it may be the responsibility of a dedicated database administrator. If you’re using a full version of SQL Server, you’ll probably use a graphical tool such as SQL Server Management Studio to create and manage your databases.
在Visual Studio中浏览和修改数据库
作为一个ASP.NET开发人员,您可能也有责任为一个web应用创造必要的数据库。另外,它可能已经存在,或者可能由专职的数据库管理员负责。如果您使用的是完整版本的SQL Server ,您可能会使用图形化工具,如SQL Server Management Studio创建和管理您的数据库。
Tip SQL Server Express doesn’t include SQL Server Management Studio in the download that you use to install it. However, you can download it separately. Just search for “SQL Server Management Studio” in your
favorite search engine or surf to http://tinyurl.com/ynl9tv.
提示:SQL Server Express的下载中不包括SQL Server Management Studio,以使您安装它。不过,您也可以单独下载它。只要在您的最喜爱的搜索引擎或浏览中搜索“SQL Server Management Studio”或到 http://tinyurl.com/ynl9tv
If you don’t have a suitable tool for managing your database, or you don’t want to leave the comfort of Visual Studio, you can perform many of the same tasks using Visual Studio’s Server Explorer window.
如果您没有合适的工具来管理你的数据库,或者你不想离开舒适的Visual Studio ,您可以使用Visual Studio的服务器资源管理器窗口执行许多相同的任务。
Here’s how you can get started. First, choose View →Server Explorer from the Visual Studio
menu to show the Server Explorer window. Then, using the Data Connections node in the
Server Explorer, you can connect to existing databases or create new ones. Assuming you’ve
installed the pubs database (see the readme.txt file for instructions), you can create a connection
to it by following these steps:
以下是您如何开始使用。首先,选择资源管理器从Visual Studio 菜单选择查看→服务器资源管理器,显示服务器资源管理器窗口。然后,通过使用服务器资源管理器中的数据连接节点,可以连接到现有的数据库,或建立新的节点。假设您安装pubs数据库(见Readme.txt文件的指示) ,您可以按照下列步骤创建一个连接:
1. Right-click the Data Connections node, and choose Add Connection. If the Choose Data Source window appears, select Microsoft SQL Server and then click Continue.
1 、右击数据连接节点,并选择添加连接。如果选择数据源窗口出现时,选择Microsoft SQL Server然后单击继续。
2. If you’re using a full version of SQL Server, enter localhost as your server name. This indicates the database server is the default instance on the local computer. (Replace this with the name of a remote computer if needed.) If you’re using SQL Server Express, you’ll need to use the server name localhost/SQLEXPRESS instead, as shown in Figure 15-2. The SQLEXPRESS part indicates that you’re connecting to a named instance of SQL Server. By default, this is the way that SQL Server Express configures itself when you first install it.
2 、如果您使用的是完整版本的SQL Server ,请输入您的本地服务器名称。这表明在本地计算机上该数据库服务器是默认实例。(如果需要,可以用一台远程计算机取代这个名称。)如果您使用的是SQL Server Express , 您需要使用本地服务器名/ SQLEXPRESS而不是图15-2所示 。SQLEXPRESS部分表明您连接到一个名为SQL Server实例。默认情况下,当您第一次安装使用, SQL Server Express自行配置。
3. Click Test Connection to verify that this is the location of your database. If you haven’t installed a database product yet, this step will fail. Otherwise, you’ll know that your database server is installed and running.
3 、单击测试连接,以确认这是数据库的位置。但是如果您还没有安装一个数据库产品,这一步骤将失败。否则,你就会知道您的数据库服务器已经安装并在运行。
4. In the Select or Enter a Database Name list, choose the pubs database. (In order for
this to work, the pubs database must already be installed. You can install it using the
database script that’s included with the sample code, as explained in the following section.)
If you want to see more than one database in Visual Studio, you’ll need to add
more than one data connection.
4 、在名称列表中选择或输入数据库,选择pubs数据库。(为了让这一步有效,pubs数据库必须已经安装。您可以使用在下面一节的解释示例代码数据库的脚安装)。如果你想在Visual Studio中看到一个以上的数据库, 您需要添加不止一个的数据连接。
 
Tip Alternatively, you can choose to create a new database by right-clicking the Data Connections node and choosing Create New SQL Server Database.
提示:或者,您也可以通过右键单击数据连接节点,选择创建一个新的数据库,创建新的SQL Server数据库。
5. Click OK. The database connection will appear in the Server Explorer window. You can now explore its groups to see and edit tables, stored procedures, and more. For example, if you right-click a table and choose Show Table Data, you’ll see a grid of records that you can browse and edit, as shown in Figure 15-3.
5 、单击确定。数据库连接将出现在服务器资源管理器窗口。您现在可以展开组,看到和编辑表格,存储过程,等等。例如,如果你右击一个表,并选择显示表数据,您会看到一个记录表格,你可以浏览和编辑,如图15-3 所示。

 


Tip The Server Explorer window is particularly handy if you’re using SQL Server Express Edition, which
gives you the ability to place databases directly in the App_Data folder of your web application (instead of
placing all your databases in a separate, dedicated location). If Visual Studio finds a database in the
App_Data folder, it automatically adds a connection for it to the Data Connections group. To learn more
about this feature, check out the “User Instance Connections” section later in this chapter.
提示:服务器资源管理器窗口是特别方便,如果你使用的是SQL Server Express版,它可以让您把数据库直接放在Web应用程序的App_Data文件夹中(而不是把您所有的数据库放在一个单独的、专用的位置) 。如果Visual Studio在 App_Data文件夹中发现一个数据库,它会自动添加一个连接到数据连接组。若要了解更多关于此功能,请查看这一章的“用户实例连接”一节。
 

 

原创粉丝点击