Microsoft KB Archive/832742

= How to deploy a .NET Framework application to run from a network location =

Article ID: 832742

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-



Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:

840667 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application



IN THIS TASK

 * SUMMARY
 * Requirements
 * Determine the trust level
 * Grant permission to the application
 * Create a console application
 * Map the network drive and deploy the compiled application
 * Assign Full Trust permission
 * REFERENCES



SUMMARY
The step-by-step article describes how to deploy an application that is built on the Microsoft .NET Framework to run from a network drive.

back to the top

Requirements
This article assumes that you are familiar with the following topic:

Programming by using Microsoft Visual Basic .NET

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
 * Microsoft Windows XP or Microsoft Windows 2000
 * Microsoft Visual Studio .NET 2003 or Microsoft Visual Studio .NET 2002

back to the top

Determine the trust level
Security is an important concern when you build an application. The common language runtime grants different levels of trust to code based on specific attributes (named evidences) that the code possesses.

When the common language runtime determines that code has a specific level of trust, the common language runtime permits the code to access resources that are protected by that level of trust. By default, a .NET Framework application that runs from the Internet does not have the same level of trust as a .NET Framework application that runs from your local computer. An application that runs from your local computer can access resources such as the file system. However, an application that runs from the Internet or from a local intranet cannot access the file system on your local computer.

Typically, the default security policy is sufficient for your application. Microsoft recommends that you change this security policy only if you must. You can use the .NET Framework configuration tool (Mscorcfg.msc) to change the security policy.

In the .NET Framework, code access security controls access to resources by controlling how code runs. When a user runs an application, the common language runtime assigns the application to any one of the following five zones:
 * My Computer - The application code is hosted directly on the user's computer.
 * Local Intranet - The application code runs from a file share on the user's intranet.
 * Internet - The application code runs from the Internet.
 * Trusted Sites - The application code runs from a Web site that is defined as &quot;Trusted&quot; in Internet Explorer.
 * Untrusted Sites - The application code runs from a Web site that is defined as &quot;Restricted&quot; in Internet Explorer.

You can set the security level for each zone to High, Medium, Medium-low, or Low.

Trust levels define the resources that the application can access. The zone, together with other security evidence, such as the publisher, the strong name, the Web site, and the URL of the code, determines the permissions that the common language runtime grants to the code at run time.

Because, you cannot control the security settings on a user's computer, your application must work within the existing settings. Therefore, some resources may not be available to your application. For example, your application may have to write data to a file. However, the user's computer may raise an exception at run time to deny write access for your application.

back to the top

Grant permission to the application
An application that is hosted on a network drive can run on your local computer. To run the application, you must grant a level of trust to the assembly that corresponds to the application. The trust level setting ranges from None to Full Trust. To run the application on your local computer, you must grant Full Trust permission to the assembly.

back to the top

Create a console application
 Start Visual Studio .NET. On the File menu, point to New, and then click Project. The New Project dialog box appears. Under Project Types, click Visual Basic Projects. Under Templates, click Console Application. Click OK. By default, the ConsoleApplication1 project and the Module1.vb file are created. On the Project menu, click Add Reference. In the Add Reference dialog box, click the .NET tab.</li> On the .NET tab, click adodb, click Select, and then click OK.</li>  Replace the existing code in the Module1.vb file with the following code. Module Module1 Sub Main Dim i As Integer Dim intMaxConnections As Integer Dim Conn As ADODB.Connection intMaxConnections = 63 Dim IntArray(intMaxConnections) As Object Console.WriteLine(&quot;Starting test...&quot;) For i = 0 To intMaxConnections Conn = CreateObject(&quot;ADODB.Connection&quot;) Conn.ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; _ & &quot;Data Source=C:\Program Files\Microsoft &quot; _ & &quot;Office\Office10\Samples\Northwind.mdb;&quot; Conn.Open Console.WriteLine(&quot;Open connection is &quot; & i)           IntArray(i) = Conn Next End Sub End Module </li> On the Build menu, click Build Solution.</li> Quit Visual Studio .NET.</li></ol>

back to the top

Map the network drive and deploy the compiled application
<ol> Do the following, depending on your operating system: <ul> On Windows XP, click Start, point to All Programs, point to Accessories, and then click Windows Explorer.</li> On Windows 2000, click Start, point to Programs, point to Accessories, and then click Windows Explorer.</li></ul>

The My Documents window appears.</li> On the Tools menu, click Map Network Drive. The Map Network Drive dialog box appears.</li> In the Drive box, select any disk drive other than your local disk drives. For example, select any disk drive between D and Z.</li> Click Browse. The Browse For Folder dialog box appears.</li> Locate and then click the folder that you want to map as a network drive, and then click OK.

Note To make sure that this step works correctly, share the network folder that you want to map as a network drive.</li> In the Map Network Drive dialog box, click Finish.</li> In Windows Explorer, copy the executable file that you created in the &quot;Create a console application&quot; section from the Bin folder in your console application folder to the mapped network drive.</li></ol>

back to the top

Assign Full Trust permission
<ol> Do the following, depending on your operating system: <ul> On Windows XP, click Start, and then click Control Panel.</li> <li>On Windows 2000, click Start, point to Settings, and then click Control Panel.</li></ul> </li> <li>Do the following, depending on the version of the .NET Framework that you are using: <ul> <li>If you are using the .NET Framework 1.1, double-click Administrative Tools, and then double-click Microsoft .NET Framework 1.1 Wizards.</li> <li>If you are using the .NET Framework 1.0, double-click Administrative Tools, and then double-click Microsoft .NET Framework Wizards.</li></ul>

The .NET Wizards window appears.</li> <li>In the .NET Wizards window, click Trust an Assembly. The Trust an Assembly dialog box appears.</li> <li>Click to select the Make changes to this computer option, and then click Next.</li> <li>Click Browse. The Choose Assembly dialog box appears.</li> <li>In the Choose Assembly dialog box, locate the executable file on the mapped network drive, and then click Open.</li> <li>In the Trust an Assembly dialog box, click Next.</li> <li>In the Trust an Assembly dialog box, move the slider to Full Trust, and then click Next.</li> <li>Click Finish.</li> <li>To run the executable file from the mapped network drive, double-click the file in Windows Explorer.</li></ol>

back to the top

<div class="references_section">