Microsoft KB Archive/317752

= How to use Server Explorer and Query Designer walkthrough =

Article ID: 317752

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q317752



IN THIS TASK
SUMMARY
 * Requirements
 * Use Visual Studio .NET Productivity with Visual Database Tools
 * Verification it Works
 * Troublehooting

REFERENCES



SUMMARY
The information in this article applies to Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Enterprise Edition and Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Architect Edition. The following steps describe how to work with some of the new key Microsoft Visual Database Tools in Visual Studio .NET or Visual Studio 2005. This article describes how to create a Database Project, generate a Create Script, and how to create and run a Stored Procedure script to add it to the database by using the Northwind database.

back to the top

Requirements
The following items describe the recommended hardware, software, network infrastructure, skills and knowledge, and service packs that you will need.
 * SQL Server 7.0 or later with the Northwind database.
 * Microsoft Visual Studio .NET Enterprise or Architect Editions.

Applies To:
 * Visual Studio.NET or Visual Studio 2005
 * Visual Basic .NET or Visual Basic 2005
 * C#
 * SQL Server

Prior Knowledge required:
 * None, but familiarity with SQL Enterprise Manager is helpful.

back to the top

Visual Studio .NET or Visual Studio 2005 Productivity-Visual Database Tools
The following steps describe how to work with some of the new key Visual Database Tools in Visual Studio .NET or in Visual Studio 2005. This article describes how to create a Database Project, generate a Create Script, and how to create and run a Stored Procedure script to add it to the database by using the Northwind database.
 * 1) Click Start, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio .NET.

Note In Visual Studio 2005, click Start, point to Programs, point to Microsoft Visual Studio .NET, and then click Microsoft Visual Studio 2005.
 * 1) Press CTRL+ALT+S to open Server Explorer.
 * 2) In Server Explorer, right-click Data Connections, and then click Add Connection.
 * 3) In the Data Link Properties dialog box, type localhost as the server name in the first drop-down list box.
 * 4) In the User name field, type sa, click to select the Blank Password check box, click Northwind in the bottom drop-down list, and then click OK.
 * 5) In Server Explorer, click Data Connections to view the connection to the Northwind database.
 * 6) Click the Northwind connection to view the various database objects that you now have access to.
 * 7) On the File menu, point to New, and then click the Project menu.
 * 8) Click Other Projects, and then click Database Projects.
 * 9) In Templates, click Data Project.
 * 10) In the Name field, type DBHowTo, and then click OK.
 * 11) In the Add Database Reference dialog box, select the Northwind connection that you just created, and then click OK.
 * 12) In Solution Explorer, right-click the Create Scripts folder, and then click Generate Create Script.
 * 13) In the SQL Server Login dialog box, click OK.
 * 14) In the Generate Create Scripts dialog box, select the first object that is listed, click Add, and then click OK.
 * 15) In the Browse for Folder dialog box, verify that the Create Scripts folder is selected under the DBHowTo folder, and then click OK.
 * 16) Click OK when the Scripting message box appears.

NOTE: A script to create the object that you selected appears under the Create Scripts folder in Solution Explorer.
 * 1) In Solution Explorer, right-click the Queries folder, and then click Add New Item.
 * 2) In Templates, click Stored Procedure, type spGetTerritoryRegions in the Name field, and then click Open.
 * 3) Right-click in the SQL Block, and then click Design SQL Block.
 * 4) In the Diagram pane, right-click the sysobjects table title bar, and then click Remove.
 * 5) Right-click the Diagram pane, and then click Add Table.
 * 6) Press and hold the CTRL key while you click both the Region and Territories tables to select both, click Add, and then click OK.
 * 7) Click the gray area to the left of the asterisk (*), and then press the DELETE key. Note that if you do not do this, the individual fields that you select will appear in the Grid pane with an alias.
 * 8) In the Territories table, click to select the TerritoryDescription check box.
 * 9) In the Region Table, click to select the RegionDescription check box.
 * 10) Click Run Query on the Query toolbar or right-click any of the panes, and then click Run to run the SQL statements.

The Results pane fills with all of the employees and their associated territories and regions.
 * 1) Press CRTL + S to save the query.
 * 2) Above the Diagram pane, click the \Queries\spGetTerritoryRegions.sql (DBHowTo) tab.
 * 3) In the PRINT statement, select Stored_Procedure_Name, and then press CTRL + H.
 * 4) In the Replace with field, type spGetTerritoryRegions, click Replace All, click OK, and then click Close.
 * 5) Press CTRL + S to save the query.
 * 6) In Solution Explorer, right-click spGetTerritoryRegions, and then click Run.

This adds the stored procedure to the database, but does not output any result set.

back to the top

Verification it Works

 * 1) A confirmation that the script executed appears in the Database Output window.
 * 2) In Server Explorer, click Stored Procedures. spGetTerritoryRegions is not listed until you click Refresh at the top of Server Explorer.

back to the top

Troubleshooting
This article assumes that your SQL Server is using mixed security and is configured with a blank SA password. If it is not or you want to use integrated security, modify step 5 in the &quot;Visual Studio .NET Productivity-Visual Database Tools&quot; section appropriately.

back to the top