I want to connect to a SSAS Server in order to detect the databases.
However, I don't know how to connect to the server in SSAS.
Whenever I connect with server.Connect(string), I get this error message:
Connection failed on Microsoft.SqlServer.Dts.Runtime.ConnectionManager with Object reference not set to an instance of an object.
Here is what my code looks like:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.AnalysisServices
Public Class ScriptMain
Dim connMgr As ConnectionManager = Dts.Connections("SSAS")
Dim server As Microsoft.AnalysisServices.Server
Dim db As Microsoft.AnalysisServices.Database
Dim connStr As String
connStr = Dts.Connections("SSAS").ConnectionString
Try
connMgr.AcquireConnection(Nothing)
MsgBox("connMgr is connected.")
server.Connect(connStr)
MsgBox("server is connected.")
Catch ex As Exception
Dts.Events.FireError(-1, "", "Connection failed on " + connMgr.ToString + " with " + ex.Message, "", 0)
End Try
For Each db In (server.Databases)
MsgBox(db.Name)
Next
End Sub
End Class
You forgot to initialize the server variable.
I think you want to do
server = connMgr.AcquireConnection(Nothing)
HTH,
Ovidiu
However,AcquireConnection(Nothing) returns an object which can not be casted to Microsoft.AnalysisServices.Server.
Error message on an explicit type cast:
Connection failed on Microsoft.SqlServer.Dts.Runtime.ConnectionManager with Unable to cast COM object of type 'System.__ComObject' to class type 'Microsoft.AnalysisServices.Server'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
So, how can I use the connection with Microsoft.AnalysisServices.Server?
|||
I'm not much of a VB guy:)
maybe it should be something like:
server = connection.AcquireConnection(Nothing) As Server
HTH,
Ovidiu
What should that statement do? (btw: it does not work)
If it should be a cast: the problem is not the cast syntax, it is that I cannot downcast the returned object, since there is some incompatibility with the COM hierarchy.
Microsoft.AnalysisServices.Server has a connect Method on its own, however, it only takes a string as argument and it fails when calling it in SSIS.
Does anybody know how to use the ConnectionManager connection in Microsoft.AnalysisServices?
|||I found the error. Some VB mistake
Server.Connnect works well ...
Thanks for your support.
No comments:
Post a Comment