How to verify an ADO connection to an OLAP Server is ok?

Hi there,

Short Story:
    Is there a way to return the system time of an OLAP server using a MDX expression?
    I am looking for the equivalent of "SELECT GETDATE()".

Long Story:
    Basically I am trying prove I have a valid and open connection to a OLAP Server that I am about to execute a MDX expression against.
    My App is dumb in the sense that I don't know the DB Schema, I am only trying to execute an expression that I will soon after pass off as a recordset.
    My code is probably going to be something like this....

    Public Function ConnectionOK(MyCon As ADODB.Connection) As Boolean
    On Error GoTo EH
    Dim lTryCount As Long
          lTryCount = 0
    Try_Again:
          lTryCount = 1 + lTryCount
        'if this next line executes without error, then assume the connection valid
          MyCon.Execute "SELECT GETDATE()" 'or what ever the MDX equivalent happens to be
          ConnectionOK = True
    LEAVE:
    Exit Function
    EH:
          If lTryCount = 1 Then
                Set MyCon = Nothing
                Set MyCon = New ADODB.Connection
                MyCon.ConnectionString = "Provider=MSOLAP;Integrated Security=SSPI;" & _
                            "trusted_connection=yes;" & _
                            "Persist Security Info=True;" & _
                            "Initial Catalog=" & m_strDBName & _
                            ";Data Source=" & m_strDataSource
                Resume Try_Again
          Else
                ConnectionOK = False
                Resume LEAVE
          End If
    End Function
LVL 2
soco180Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkaiosIT DirectorCommented:
You can try something like this:

Private Sub Command1_Click()
   Dim ok as boolean
   ok = OpenConn(myCon)
End Sub


Public Function OpenConn(cn As ADODB.Connection) As Boolean

   On Error GoTo Err_Handler
   
   If (cn.State = adStateOpen) Then
      OpenConn = True
      Exit Function
   End If
   
   With cn
      .Provider = "MSOLAP"
      .Properties("Data Source") = m_strDataSource
      .Properties("Initial Catalog") = m_strDBName
      .Properties("Integrated Security") = "SSPI"
      .Properties("Trusted_Connection") = "Yes"
      .Open
   End With
   
   OpenConn = (cn.State = adStateOpen)
   
   Exit Function
Err_Handler:
   OpenConn = False

End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
soco180Author Commented:
Hi JKaios, thanks for your help...However I am trying to avoid relying on the cn.State as a rule. That is why I am trying to figure out an MDX statement that I can execute without having to know the Cube Schema.

On SQL Server I executed a simple T-SQL statement "Select GetDate()" on my connection. If that failed I would re-init my connection and try again.

Now I plan to call the ConnectionOk function each time I am about to execute an actual MDX statement for real data.


If I knew how to re-title this thread topic I would call it "Need simple MDX statement independent of Cube Schema".
0
soco180Author Commented:
Because it is my fault that I didn't ask the correct question and I didn't give the question a proper title, I am accepting JKAIOS answer because it is a valid answer to the actual question I posted.

I will turn around and post a new question that goes like this...

"Is there a MDX statement that can be executed without knowing Cube Schema, something like this "SELECT GETDATE()" in T-SQL? It can be any MDX statement as long as it is fast and completely independent of the Cube Schema."
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.