Problem: MDX works in Sample Application, but not in .net -
05-01-2006
, 04:11 PM
I have the MDX below which works fine in the Sample Application, but gives an
error when I try it in a vb.net application. The weirder part is, that it
DOES work in vb.net for the FoodMart 2000 Sales cube, but when I do it in
vb.net for one of my cubes, it errors out. Both MDX versions work in the
Sample Application. Is there something unique about the Sales Time
dimension? I have tried to recreate my time dimensions the exact way, but
something is still not right. Has anyone hit a similar situation? I'm
stuck. Thank you.
here is the error message in the vb.net application:
Cannot connect to the server ''. The server is either not started or too
busy.
here is the mdx that works in FoodMart 2000:
WITH MEMBER [Time].[YTD Current] as 'SUM(YTD([Time].[1998].[Q1].[3]),
[Measures].currentmember)'
MEMBER [Time].[YTD Last Year] as 'SUM(YTD([Time].[1997].[Q1].[3]),
[Measures].currentmember)'
MEMBER [Time].[YTD Variance] as '[Time].[YTD Current]-[Time].[YTD Last
Year]', solve_order=10
SELECT {[Measures].[Store Sales],[Measures].[Sales Count]} on columns,
{[Time].[YTD Current],[Time].[YTD Last Year],[Time].[YTD Variance]} on rows
FROM Sales
here is the vb code:
Imports ADODB
Imports ADOMD
Imports System.Data.OleDb
Public Class AccountDash
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim sMDX As String
Dim sMDX As String
sMDX = "WITH MEMBER [Time].[YTD Current] as
'SUM(YTD([Time].[1998].[Q1].[3]), [Measures].currentmember)' "
sMDX = sMDX & "MEMBER [Time].[YTD Last Year] as
'SUM(YTD([Time].[1997].[Q1].[3]), [Measures].currentmember)' "
sMDX = sMDX & "MEMBER [Time].[YTD Variance] as '[Time].[YTD
Current]-[Time].[YTD Last Year]', solve_order=10 "
sMDX = sMDX & "SELECT {[Measures].[Store Sales],[Measures].[Sales
Count]} on columns, {[Time].[YTD Current],[Time].[YTD Last Year],[Time].[YTD
Variance]} on rows FROM Sales "
' Connect to the OLAP server
Dim cn As New ADODB.Connection
cn.Open("provider=msolap;data source=SERVERNAME")
cn.DefaultDatabase = "FoodMart 2000"
' Create a cellset
Dim cs As New ADOMD.Cellset
'cs = Server.CreateObject("ADOMD.Cellset")
cs.ActiveConnection = cn
cs.Open(sMDX)
'display the cellset
Me.dgAnnualSales.DataSource = New DataView(getDataTable(cs))
Me.dgAnnualSales.DataBind()
'clear the resources
cs.Close()
cn.Close()
End Sub
Private Function getDataTable(ByRef cs As Cellset) As DataTable
'design the datatable
Dim dt As New DataTable
Dim dc As DataColumn
Dim dr As DataRow
'add the columns
dt.Columns.Add(New DataColumn("-")) 'first column
'get the other columns from axis
Dim p As Position
Dim name As String
Dim m As Member
For Each p In cs.Axes(0).Positions
dc = New DataColumn
name = ""
For Each m In p.Members
name = name + m.Caption + " "
Next
dc.ColumnName = name
dt.Columns.Add(dc)
Next
'add each row, row label first, then data cells
Dim y As Integer
Dim py As Position
y = 0
For Each py In cs.Axes(1).Positions
dr = dt.NewRow 'create new row
' Do the row label
name = ""
For Each m In py.Members
name = name + m.Caption + "<BR>"
Next
dr(0) = name 'first cell in the row
' Data cells
Dim x As Integer
For x = 0 To cs.Axes(0).Positions.Count - 1
dr(x + 1) = cs(x, y).FormattedValue 'other cells in the row
Next
dt.Rows.Add(dr) 'add the row
y = y + 1
Next
Return dt
End Function
End Class |