Microsoft KB Archive/826309

= PRB: Cannot Connect to the Analysis Server from an ASP.NET Application =

PSS ID Number: 826309

Article Last Modified on 8/22/2003

-

The information in this article applies to:


 * Microsoft SQL Server 2000 Analysis Services
 * Microsoft Visual Basic .NET (2002)
 * Microsoft Visual Basic .NET (2003)
 * Microsoft Visual C# .NET (2002)
 * Microsoft Visual C# .NET (2003)

-



Important This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows Registry



SYMPTOMS
When you try to connect to the remote server that is running Analysis Services by using an ASP.NET application, you may receive the following error message:

Description: An unhandled exception occurred during the execution of the current Web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException:



CAUSE
By default, ASP.NET applications run in the security context of the local ASPNET account. Because the local ASPNET account does not have the required permissions to access remote resources, the connection fails.



WORKAROUND
To work around the problem, you must enable impersonation in the ASP.NET application. To enable impersonation, add one of the following lines to the Web.Config file of the ASP.NET application: 

-or-





MORE INFORMATION
When a remote server tries to connect to the server that is running Analysis Services, the user information is logged to the Application Event Log. To enable event logging, follow these steps:

WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.
 * 1) In the server that is running Analysis Services, on the Taskbar, click Start, and then click Run.
 * 2) In the Run dialog box type regedit in the Open text box, and then click OK.
 * 3) In the Registry Editor window, locate the following Registry key:
 * 4) In the right pane of the Registry Editor window, double-click the AuditEvents REG_DWORD.
 * 5) In the Edit DWORD Value dialog box, in the Value data text box, type 15.
 * 6) Under the Base section, click to select the Decimal option, and then click OK.
 * 7) Close the Registry Editor window.

Steps to Reproduce the Behavior
 Create a new Visual Basic ASP.NET Web Application. Add a reference to the Microsoft ActiveX Data Objects 2.x Library. To do so, follow these steps:  On the Project menu, click Add Reference. In the Add Reference dialog box, click the COM tab. Under the Component Name section, locate Microsoft ActiveX Data Objects 2.x Library, and then click Select.</li> Click OK.</li></ol> </li> Add a Button control to the WebForm.</li> Right-click the Button control, and then click Properties.</li> In the Properties dialog box, change the button ID value to testButton, and then change the Text value to Test Button.</li>  Add the following code to the testButton_Click method of WebForm: Const strConnect = &quot;Data Source=<serverName>;PROVIDER=MSOLAP;INITIAL CATALOG=FoodMart 2000&quot; Const strSQL = &quot;Select {[Measures].[Unit Sales]} on columns, &quot; & _ &quot;Non Empty [Store].[Store Name].members on rows From Sales&quot; Dim adoCn As ADODB.Connection adoCn = New ADODB.Connection With adoCn .ConnectionString = strConnect .CommandTimeout = 20 .Open End With

Dim adoRs As ADODB.Recordset adoRs = New ADODB.Recordset With adoRs .ActiveConnection = adoCn .Open(strSQL) End With

While Not adoRs.EOF Response.Write(adoRs.Fields(0).Value) adoRs.MoveNext End While Note Replace < > with the Analysis Services server name. </li> To run the application, on the Debug menu, click Start.</li> On WebForm, click Test Button.</li></ol>

<div class="references_section">