Microsoft KB Archive/824006

= How To: Use the Estimates Sample When the Database and the Web Server Are on Different Computers =

Article ID: 824006

Article Last Modified on 2/3/2006

-

APPLIES TO


 * Microsoft Office Excel 2003
 * Microsoft Visual Studio Tools for the Microsoft Office System version 2003

-





IN THIS TASK

 * SUMMARY
 * Set up the SQL Server Database
 * Build and Deploy the ContosoQuote Web Service
 * Build the Managed Code Extension
 * Try It Out



SUMMARY
The Estimates sample that is included with Microsoft Visual Studio Tools for the Microsoft Office System describes how to use managed code extensions and how those managed code extensions can work together with Microsoft SQL Server databases and Web services. The instructions for the Estimates sample assume that both your installation of SQL Server and your installation of Web server are local to your development computer. This article describes the steps and the code changes that you can use for the Estimates sample when your SQL Server and your Web Server are on computers other than the development computer.

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.

Before you complete the steps in this article, you must first copy all files for the Estimates sample from the Visual Studio Tools for Office documentation to the development computer. The default location for the files for the Estimates sample is:

%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  and the Web server name. You must replace  and   with the names of your servers.

back to the top

Set up the SQL Server Database

 * 1) Start a command prompt.
 * 2) 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
 * 1) Run Setup.bat by using the name of your computer that is running SQL Server as the parameter. An example follows:

setup.bat 
 * 1) Close the command prompt window.

back to the top

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.</ol> </li> 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.</li> Double-click C:\Inetpub\wwwroot\ContosoQuote\ContosoQuote.sln to open the solution in Visual Studio .NET.</li> In Microsoft Solution Explorer, right-click ContosoQuote.asmx, and then click View Code.</li>  Locate the following connection string in the InitializeConnection method in ContosoQuote.asmx: Private Sub InitializeConnection Me.dbConnection = New SqlConnection(&quot;Integrated Security=SSPI;&quot; + _               &quot;Initial Catalog=EstimatesSample;Data Source=localhost;&quot;) End Sub Replace  in the connection string with the name of the database server where you created the EstimatesSample database: Private Sub InitializeConnection Me.dbConnection = New SqlConnection(&quot;Integrated Security=SSPI;&quot; + _                   &quot;Initial Catalog=EstimatesSample;Data Source=MySQLServer;&quot;) Sub </li> On the Build menu, click Rebuild Solution.</li> Deploy the Web service to your Web server: <ol style="list-style-type: lower-alpha;"> In Solution Explorer, click the ContosoQuote project.</li> 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.</li></ol> </li> On the File menu, click Close Solution.</li></ol>

back to the top

Build the Managed Code Extension
<ol> On the File menu, click Open Solution to open the Estimates solution.

The default location is ..\Samples\Office Projects\Estimates\Estimates.sln.</li> In Solution Explorer, right-click the ContosoQuote project, and then click Remove. Click OK when you are prompted to confirm the deletion.</li> Update the Web References for each of the projects in the Estimates solution. For each project in the solution, follow these steps: <ol style="list-style-type: lower-alpha;"> In Solution Explorer, double-click the project.</li> Double-click Web References, and then select Contoso.</li> 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.</li></ol> </li>  In the ThisWorkbook.vb module of the Estimates project, locate the connection string in the InitializeConnections method: Private Sub InitializeConnections Me.dbConnection = New SqlConnection(&quot;Integrated Security=SSPI;&quot; + _               &quot;Initial Catalog=EstimatesSample;Data Source=localhost;&quot;) End Sub Replace  with the name of the database server where you created the EstimatesSample database: Private Sub InitializeConnections Me.dbConnection = New SqlConnection(&quot;Integrated Security=SSPI;&quot; + _                   &quot;Initial Catalog=EstimatesSample;Data Source=MySQLServer;&quot;) Sub </li> <li>In Solution Explorer, right-click QuoteSelector.vb, and then click View Code.</li> <li> Locate the connection string for OleDbConnection1 in the InitializeComponent method: Me.OleDbConnection1.ConnectionString = _ &quot;Provider=SQLOLEDB;Integrated Security=SSPI;&quot; + _ &quot;Initial Catalog=EstimatesSample;Data Source=(local);&quot; Change the name for the database server as follows: Me.OleDbConnection1.ConnectionString = _ &quot;Provider=SQLOLEDB;Integrated Security=SSPI;&quot; + _ &quot;Initial Catalog=EstimatesSample;Data Source=MySQLServer;&quot; </li> <li>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 &quot;How to: Grant Permissions to Folders and Assemblies&quot; topic in the Visual Studio Tools for Office documentation.</li> <li>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 &quot;A Project with an Output Type of Class Library Cannot Be Started Directly&quot; topic in the Visual Studio Tools for Office documentation.</li> <li>In Microsoft Windows Explorer, mark Estimates.xls as read-only so that it acts as a template.</li></ol>

back to the top

Try It Out

 * 1) Press F5 to build and to run the solution.
 * 2) To test the solution, follow the steps in the &quot;How the Document Works&quot; section of the Estimates topic.

back to the top

Keywords: kbhowto kbhowtomaster KB824006

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.