【问题标题】:How can I access a SQL Server database with . in name via set-location如何使用 .在名称中通过设置位置
【发布时间】:2014-09-22 16:38:09
【问题描述】:

问题在标题中。我有一个数据库服务器,其中有许多名称中有句点的数据库(它们是 url,以便我知道哪个数据库与哪个站点相关联,例如 foo.bar.com_content)。当我导航到SQLSERVER:\sql\[server]\default\databases 并运行get-childitem 时,我可以很好地看到我所有数据库的列表。当我尝试cd [database name with period] 时,出现以下错误:

Set-Location : SQL Server PowerShell provider error: The number of keys specified does not match the number of keys required to address this object. The number of keys required are: Name.
At line:1 char:3
+ cd <<<<  '[database name with periods here]'
    + CategoryInfo          : InvalidData: (SQLSERVER:\sql\...t.org_Content:SqlPath) [Set-Location], GenericProviderException
    + FullyQualifiedErrorId : KeysNotMatching,Microsoft.PowerShell.Commands.SetLocationCommand

那个错误重复了四次,接着是:

Set-Location : Cannot find path 'SQLSERVER:\sql\[servername]\default\databases\[database name with periods here]' because it does not exist.
At line:1 char:3
+ cd <<<<  '[database name with periods here]'
    + CategoryInfo          : ObjectNotFound: (SQLSERVER:\sql\...t.org_Content:String)     [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

我可以在同一台服务器上对名称中没有句点的数据库运行相同的命令并正常连接。

我在 Powershell ISE、Powershell v2.0 中的 Windows 桌面计算机上运行此程序,并安装了 SQL Server 2012 工具。远程数据库服务器正在运行 SQL Server 2008r2。

【问题讨论】:

    标签: sql sql-server powershell sqlps


    【解决方案1】:

    考虑到数据库名称为foo.bar.com_content,请尝试将句点. 更改为它的十六进制值%2e,如下所示。

    cd [foo%2ebar%2ecom_content]
    

    【讨论】:

      【解决方案2】:

      Rahul 的回答通常是正确的,但请去掉括号。这是对 Rahul 答案的更正。

      cd foo%2ebar%2ecom_content
      

      如果您的命名约定使用空格,则将其括在引号中(单引号或双引号都可以)

      cd 'foo%2eb ar%2ecom_content'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-18
        • 2020-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多