ConnectionString 属性不打印连接字符串 [英] ConnectionString property not printing connection string

查看:49
本文介绍了ConnectionString 属性不打印连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下脚本获取数据库数据源的连接字符串:

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

没有输出.

我试过这样调试:

$Analysis_Server.Databases

这会打印出服务器上的所有数据库

this prints out all databases on the server

如果我索引它$Analysis_Server.Databases[],它打印任何被索引的数据库(所以在我的例子中,7,打印数据库8)

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

以下每一行的作用:

   $Analysis_Server.Databases

打印出来

人们可以注意到的一件事是,由于某种原因,它们打印出来的顺序不是按照它们在分析服务器上的顺序,如图所示......我不知道为什么会这样

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]

既然索引 0 起作用了,我们应该能够索引 [1]、[2] 等...

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

所以下面

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

印刷品:

现在进入连接字符串:

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

打印出来:

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

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

它似乎是 Database8 的连接字符串

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

然而,没有打印!似乎打印的唯一索引是 Databases[0]

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

这是 $Analysis_Server.Databases[0].DataSources[0] 打印的内容:

我们应该能够对所有数据库做同样的事情

we should be able to do the same for all databases

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

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

但没有打印任何内容!

推荐答案

我只是稍微玩了一下,以确保我理解您所面临的问题.在同一个盒子上,仍然加载了最新的可用 SqlServer PowerShell 模块 - 我得到了这些结果.

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

您能否花点时间尝试安装最新的 SqlServer PowerShell 模块,看看这对您和您面临的问题是否有任何影响?

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?

这篇关于ConnectionString 属性不打印连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆