Starting SQL Server Management Studio Express
The SQL Server Management Studio Express product allows you to manage instances of SQL Server. By manage, I mean that you can interact with the databases hosted on a given SQL Server instance. To help make this principle more concrete, start SQL Server Management Studio Express from the Windows Start menu. The actual program icon for SQL Server Management Studio Express is installed as a submenu item under the Microsoft SQL Server 2005 program group: Start > All Programs > Microsoft SQL Server 2005.
When you start the SQL Server Management Studio Express application, a connection is made automatically to the installed instance of SQL Server, as shown in Figure 1. The server name in Figure 1 is made up of the name of the host machine (in this case, LAPTOP1) and the instance of SQL Server (SQLEXPRESS in this example).
Figure 1 Connecting to an instance of SQL Server.
When you're finished, click the Connect button in the dialog box. After a minute or so, the main SQL Server Management Studio Express screen will appear (see Figure 2).
Figure 2 Successful connection to the SQL Server instance.
What exactly is the SQL Server Management Studio Express application? In Figure 2, notice the term Object Explorer displayed at the top of the left panethis program is a kind of explorer application that allows you to look at database engine instances. Think about the power of this window's contentsyou can review a significant amount of information here concerning all your database instances. Let's play around with the Object Explorer window a bit so you can get a feel for the application.
In the left pane, click the plus sign to the left of the Databases folder icon. This action displays all the databases hosted by the given instance of SQL Server (see Figure 3).
Figure 3 The resident databases hosted on SQLEXPRESS.
The first thing to notice about the databases in Figure 3 is that they're all related to SQLEXPRESS; in other words, there is no application database. Let's remedy this situation by installing a new database.
Microsoft provides many sample databases for use with SQL Server products. The one I used for this example is called pubs. (Sadly, the pubs database has nothing to do with alcoholic beverages, but instead models a fictitious publishing company.) You can download the pubs database and install it to use for your own experiments, or you can use your own database.
Running the installer will deploy the pubs database correctly, but you have to attach it manually in SQL Server Management Studio Express. This step sounds difficult, but manual attachment is actually easy. Click the File button and browse to the script file instpubs.sql (see Figure 4). Mine is located in the following path:
C:\SQL Server 2000 Sample Databases\instpubs.sql
Select the file and click Open. When the script file opens, click the Execute button in the toolbar (see Figure 5).
Figure 4 Running the pubs database script.
Figure 5 Just before the instpubs.sql script is executed.
If all is well with your setup, a new database called pubs should appear in the list in the left pane, as shown in Figure 6.
Figure 6 Just after attaching to the pubs database.
If you expand the pubs database by clicking its plus sign, you can see the constituent tables, as illustrated in Figure 7.
Figure 7 Just after successfully installing the pubs database.
Our database is finally in place and ready for programmatic access via C#. That's all I'll be doing with SQL Server Management Studio Express for this article. As the figures have shown, this product provides a nice environment with which to administer your SQL Server databases. Now let's see how to access such databases programmatically, using Visual C# 2008 Express Edition.