Search code examples
sqlsql-serverpowershellazure-analysis-services

ConnectionString property not printing connection string


I am trying to get the connection string of a database datasource with the following script:

   $Analysis_Server = New-Object Microsoft.AnalysisServices.Server  
   $Analysis_Server.connect("$server") 

   $database = $Analysis_Server.Databases[7]
   $c = $database.DataSources[0].ConnectionString
   $c

nothing is outputting.

I have tried debugging like so:

$Analysis_Server.Databases

this prints out all databases on the server

if i index it $Analysis_Server.Databases[], it prints whatever database is indexed (so in my case, 7, prints database8)

clearly the Database property is working.

-------------UPDATE:--------------

here is how the Databases look in the server

server1_Databses

here is what each of the following lines does:

   $Analysis_Server.Databases

this prints out

Databses

One thing one can notice is for some reason they are printed out not in order of how they are on the analysis server as in the picture...I dont know why that is the case

this is what this command prints out:

Analysis_Server.Databases[0]

Database8

Now since index 0 worked, we should be able to index [1], [2], etc...

so the following

Analysis_Server.Databases[1] 
Analysis_Server.Databases[2]

prints:

databases1 and 3

Now unto the connection string:

$Analysis_Server.Databases[0].DataSources[0].ConnectionString

that prints out:

Connection Timeout=60;User Id=someID;Data Source=10.10.10.10;Persist Security Info=True

its appears to be the connection string for Database8

cool, so then we should be able to do this as well:

$Analysis_Server.Databases[1].DataSources[0].ConnectionString

However, nothing prints! the only index that seems to print is with Databases[0]

This is what $Analysis_Server.Databases[0].DataSources[0] prints:

DataSources0

we should be able to do the same for all databases

$Analysis_Server.Databases[1].DataSources[0]

$Analysis_Server.Databases[2].DataSources[0] etc..

but nothing gets printed!


Solution

  • I just played with things a little more, to make sure I understood the issue that you are facing. On the same box, still with the newest available SqlServer PowerShell module loaded - I get these results.

    PS C:\Users\Administrator> $Analysis_Server = New-Object Microsoft.AnalysisServices.Server
    PS C:\Users\Administrator> $Analysis_Server.connect("AX2012R2A")
    PS C:\Users\Administrator> $Analysis_Server.Databases
    
    Name                                     State                Read-Write Mode
    ----                                     -----                ---------------
    Demand Forecast ps                       Processed            ReadWrite
    Demand Forecast Accuracy ps              Processed            ReadWrite
    Demand Forecast Accuracy initial         Processed            ReadWrite
    Dynamics AX ps                           Processed            ReadWrite
    Demand Forecast initial                  Processed            ReadWrite
    Dynamics AX initial                      Processed            ReadWrite
    

    Now I traverse every database and their datasources, to display the connection string

    PS C:\Users\Administrator> $Analysis_Server.Databases | ForEach-Object {$_.datasources}
    
    Name                      Isolation     Max Connections Connection String
    ----                      ---------     --------------- -----------------
    Dynamics Database         ReadCommitted              10 Provider=SQLNCLI11.1;Data
                                                            Source=AX2012R2A;Integrated
                                                            Security=SSPI;Initial
                                                            Catalog=DatabaseName_4
    Dynamics Database         ReadCommitted              10 Provider=SQLNCLI11.1;Data
                                                            Source=AX2012R2A;Integrated
                                                            Security=SSPI;Initial
                                                            Catalog=DatabaseName_2
    Dynamics Database         ReadCommitted              10 Provider=SQLNCLI11.1;Data
                                                            Source=AX2012R2A;Integrated
                                                            Security=SSPI;Initial
                                                            Catalog=DatabaseName_1
    Dynamics Database         ReadCommitted              10 Provider=SQLNCLI11.1;Data
                                                            Source=AX2012R2A;Integrated
                                                            Security=SSPI;Initial
                                                            Catalog=DatabaseName_6
    Dynamics Database         ReadCommitted              10 Provider=SQLNCLI11.1;Data
                                                            Source=AX2012R2A;Integrated
                                                            Security=SSPI;Initial
                                                            Catalog=DatabaseName_3
    Dynamics Database         ReadCommitted              10 Provider=SQLNCLI11.1;Data
                                                            Source=AX2012R2A;Integrated
                                                            Security=SSPI;Initial
                                                            Catalog=DatabaseName_5
    

    And the one-liner that just gives you the connection string and nothing else

    PS C:\Users\Administrator> $Analysis_Server.Databases | ForEach-Object {$_.datasources | ForEach-Object {$_.ConnectionSt
    ring}}
    Provider=SQLNCLI11.1;Data Source=AX2012R2A;Integrated Security=SSPI;Initial Catalog=DatabaseName_4
    Provider=SQLNCLI11.1;Data Source=AX2012R2A;Integrated Security=SSPI;Initial Catalog=DatabaseName_2
    Provider=SQLNCLI11.1;Data Source=AX2012R2A;Integrated Security=SSPI;Initial Catalog=DatabaseName_1
    Provider=SQLNCLI11.1;Data Source=AX2012R2A;Integrated Security=SSPI;Initial Catalog=DatabaseName_6
    Provider=SQLNCLI11.1;Data Source=AX2012R2A;Integrated Security=SSPI;Initial Catalog=DatabaseName_3
    Provider=SQLNCLI11.1;Data Source=AX2012R2A;Integrated Security=SSPI;Initial Catalog=DatabaseName_5
    

    Could you take the time and try to install the latest SqlServer PowerShell module and see if that makes any difference for you and the problem that you are facing?