The steps in this article assume the following:
- Microsoft SQL Server 2000 or Microsoft SQL Server Desktop Engine (MSDE) 2000 is installed on the computer that you will use for the sample database.
- Internet Information Services (IIS) is installed on the computer that you will use for the sample Web service.
- Microsoft Visual Studio .NET 2003, Visual Studio Tools for Office, and Microsoft Office 2003 System are installed on the development computer where you will build the solution and then run the Office managed code extension.
%userprofile%\My Documents\Samples\Office Projects\Estimates\Database
Note The steps and the code that are illustrated in this article use the SQL Server name MySQLServer and the Web server name MyWebServer. You must replace MySQLServer and MyWebServer with the names of your servers.
Set up the SQL Server Database
- Start a command prompt.
- At the command prompt, change to the directory that contains the Database subfolder.
An example follows:
cd %userprofile%\My Documents\Samples\Office Projects\Estimates\Database - Run Setup.bat by using the name of your computer that is running SQL Server as the parameter. An example follows:
setup.bat MySQLServer - Close the command prompt window.
Build and Deploy the ContosoQuote Web Service
- Create a new Microsoft ASP.NET Web service in Microsoft Visual Basic .NET as follows:
- Start Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- In the Project Types list, select Visual Basic Project. In the Templates list, select ASP.NET Web Service.
- In the Location box, type http://localhost/ContosoQuote, and then click OK.
- On the File menu, click Close Solution.
- Copy all the files that are in ..\Samples\Office Projects\Estimates\ContosoQuote to the folder that contains your new Web service project.
Note The default location for your new Web service project is C:\Inetpub\wwwroot\ContosoQuote. - Double-click C:\Inetpub\wwwroot\ContosoQuote\ContosoQuote.sln to open the solution in Visual Studio .NET.
- In Microsoft Solution Explorer, right-click ContosoQuote.asmx, and then click View Code.
- Locate the following connection string in the InitializeConnection method in ContosoQuote.asmx:Replace localhost in the connection string with the name of the database server where you created the EstimatesSample database:
Private Sub InitializeConnection() Me.dbConnection = New SqlConnection("Integrated Security=SSPI;" + _ "Initial Catalog=EstimatesSample;Data Source=localhost;") End Sub
Private Sub InitializeConnection() Me.dbConnection = New SqlConnection("Integrated Security=SSPI;" + _ "Initial Catalog=EstimatesSample;Data Source=MySQLServer;") Sub
- On the Build menu, click Rebuild Solution.
- Deploy the Web service to your Web server:
- In Solution Explorer, click the ContosoQuote project.
- On the Project menu, click Copy Project.
Provide the URL to your Web server as the destination. For example, type http://MyWebServer/ContosoQuote, and then click OK.
- On the File menu, click Close Solution.
Build the Managed Code Extension
- On the File menu, click Open Solution to open the Estimates solution.
The default location is ..\Samples\Office Projects\Estimates\Estimates.sln. - In Solution Explorer, right-click the ContosoQuote project, and then click Remove. Click OK when you are prompted to confirm the deletion.
- Update the Web References for each of the projects in the Estimates solution. For each project in the solution, follow these steps:
- In Solution Explorer, double-click the project.
- Double-click Web References, and then select Contoso.
- In the Properties window, change Web Reference URL to http://MyWebServer/ContosoQuote/ContosoQuote.asmx.
Note If the Properties window does not appear, press F4 to make the window appear.
- In the ThisWorkbook.vb module of the Estimates project, locate the connection string in the InitializeConnections method:Replace localhost with the name of the database server where you created the EstimatesSample database:
Private Sub InitializeConnections() Me.dbConnection = New SqlConnection("Integrated Security=SSPI;" + _ "Initial Catalog=EstimatesSample;Data Source=localhost;") End Sub
Private Sub InitializeConnections() Me.dbConnection = New SqlConnection("Integrated Security=SSPI;" + _ "Initial Catalog=EstimatesSample;Data Source=MySQLServer;") Sub
- In Solution Explorer, right-click QuoteSelector.vb, and then click View Code.
- Locate the connection string for OleDbConnection1 in the InitializeComponent method:Change the name for the database server as follows:
Me.OleDbConnection1.ConnectionString = _ "Provider=SQLOLEDB;Integrated Security=SSPI;" + _ "Initial Catalog=EstimatesSample;Data Source=(local);"
Me.OleDbConnection1.ConnectionString = _ "Provider=SQLOLEDB;Integrated Security=SSPI;" + _ "Initial Catalog=EstimatesSample;Data Source=MySQLServer;"
- Grant full trust to the directory that is named ..\Samples\Office Projects\Estimates\* by adding the directory to the OfficeProjects code group.
For additional information, see the "How to: Grant Permissions to Folders and Assemblies" topic in the Visual Studio Tools for Office documentation. - Change the Start Action property of the project to start Microsoft Excel, and then change the command line arguments to point to the Estimates.xls
workbook.
For additional information, see the "A Project with an Output Type of Class Library Cannot Be Started Directly" topic in the Visual Studio Tools for Office documentation. - In Microsoft Windows Explorer, mark Estimates.xls as read-only so that it acts as a template.
Try It Out
- Press F5 to build and to run the solution.
- To test the solution, follow the steps in the "How the Document Works" section of the Estimates topic.