Showing posts with label sometimes I hate auto-complete. Show all posts
Showing posts with label sometimes I hate auto-complete. Show all posts

December 10, 2009

Querying SSAS with SQL

I spent the better part of two days attempting to set up a SQL Server Analysis Services (SSAS) server as a linked server to a master database, with the chief goal of querying financial data for display through a ColdFusion web interface. My version of ColdFusion does not easily support an MSOLAP connection, but a little research turned up an ostensibly easy method for querying SSAS by way of normal SQL Server data source. Simply adding the data repository as a linked server failed spectacularly and produced a number of infuriating and worthless error messages, not limited to:

OLE DB provider "MSOLAP" for linked server "<servername>" returned message "An error was encountered in the transport layer.".

OLE DB provider "MSOLAP" for linked server "<servername>" returned message "The peer prematurely closed the connection.".

Cannot initialize the data source object of OLE DB provider "MSOLAP" for linked server "<servername>".

After combing through a plethora of confused Google results, giving up in frustration and starting again fresh the next day, I managed to get it working; I figured I'd catalog my trials for posterity. I'm working on Microsoft SQL Server 2005, 64-bit Enterprise edition. Any text contained in < >s is a placeholder for plaintext.

sp_addlinkedserver
@server='<SSAS server name or handle>',
@provider='MSOLAP',
@srvproduct = '',
@datasrc='<actual server name>',
@catalog='<database with the cubes you want to query>'

Innocuous enough, but I was stuck here for several reasons. I am an SSAS/MDX newbie and many suggestions insisted that the SSAS database must be wrapped in [ ]s — wrong. My connection defaulted to a different database when I didn't specify an initial catalog and it outright failed when I included the brackets. Is there an MDX command to switch databases? Apparently not.

Additionally, the linked server defaults to the current security context to make the connection, which is a problem when you're logged in as sa (best practices fail, I know). For whatever reason, you can only use an Active Directory (AD) account to log into SSAS. You can check this setting in the Properties menu (Security tab) for your freshly created linked server. You can probably do this with the provider string parameter to sp_addlinkedserver, too, but I wasn't sure if I'd need a complete provider string or if I could just use

User Id=<domain\username>&Password=<password>
and I was in no mood to experiment. At first I received a delegation error, which led me on a goose chase for a solution in AD, but the AD account just needed the proper permissions on the SSAS server (I set mine up in the serveradmin role, but that is probably overkill).

Finally, in order for

select *
from openquery(<SSAS server handle>, '<MDX query>')
to work, I needed to go into Server Objects > Linked Servers > Providers > MSOLAP > Properties and Enable "Allow Inprocess".

And now I can query an SSAS server through an already existed ColdFusion DSN for the master database.