Microsoft KB Archive/823066

= PRB: Cannot Administer Analysis Services by Using DSO in ASP.NET =

Article ID: 823066

Article Last Modified on 5/18/2007

-

APPLIES TO


 * Microsoft SQL Server 2000 Analysis Services
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition

-



SYMPTOMS
When you try to use Microsoft Decision Support Objects (DSO) from an ASP.NET application to perform administrative tasks on a server that is running Analysis Services, you may receive an error similar to the following:

When connecting to the local computer that is running Analysis Services:

Cannot connect to the Analysis server on computer 'MyServer'. Connection to the server is lost

When connecting to a remote computer that is running Analysis Services:

Cannot open connection to Analysis server 'MyRemoteServer'. Error in data [Possible data corruption]



CAUSE
This behavior occurs for two separate reasons. One part of the issue involves the start permissions of the DSO ActiveX DLL. By default, the ActiveX DLLs are carried out in the ASP.NET worker process (Aspnet_wp.exe) under the ASPNET account, when called from an ASPX page.

The other part of the issue is, Aspnet_wp.exe uses a Multi-Threaded Apartment (MTA) model, while DSO uses a Single-Threaded Apartment (STA) model. With the ASP.NET application, the impersonation token is on one of the applications MTA threads and the STA COM component is accessed by a different thread (the single thread in its STA). Because the MTA threads impersonation token is not passed to the STA thread, the STA thread carries out under the security token associated with the Aspnet_wp.exe process.



WORKAROUND
To work around the problem, you must enable impersonation in the ASP.NET application. To do so, follow these steps:   To enable impersonation, add one of the following lines to the Web.Config file of the ASP.NET application:  -or-    To continue to use the impersonation token during and after the MTA to STA switch, add the following attribute to the <@Page> directive at the top of the HTML tab for the ASPX page: aspcompat=&quot;true&quot; 



Steps to Reproduce the Behavior
 Create a new Visual Basic ASP.NET Web Application. Add a reference to the Microsoft Decision Support Objects COM object. To do so, follow these steps:  Click Tools, and then click Add Reference....</li> In the Add Reference wizard, click the COM tab.</li> Locate, and then click to select Microsoft Decision Support Objects.</li> Click Select, and then click OK.</li></ul> </li> From the Toolbox, drag a Button control onto the WebForm.</li> Right-click the Button control, and then click Properties.</li> In the Properties pane, change the button ID value to testButton, and change the Text value to Test Button.</li>  Add the following code to the testButton_Click method of the WebForm: ' Create a DSO.Server object. Dim oDsoServer As DSO.Server oDsoServer = New DSO.Server Try ' Try to connect to the server. oDsoServer.Connect(&quot;<Server Name>&quot;) ' Connection was successful, so display a message. Response.Write(&quot;Connection OK&quot;) ' We're finished with the server, so close it. oDsoServer.CloseServer Catch ex As Exception ' Connection failed so display an error. Response.Write(ex.Message.ToString) End Try Note Replace < > with the Analysis Services server name. </li> To run the application, click Debug, and then click Start.</li> On the WebForm, click Test Button.</li></ol>

<div class="references_section">