How to verify an ADO connection to an OLAP Server is ok?
Posted on 2007-04-09
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()".
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
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
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
ConnectionOK = False