sql - 如何使用来访问SQL Server数据库。通过设置位置的名称

标签 sql sql-server powershell sqlps

问题在标题中。我有一个数据库服务器,该服务器具有多个名称中带有句点的数据库(它们是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的Windows台式机上运行此程序,安装了SQL Server 2012工具的Powershell v2.0。远程数据库服务器正在运行SQL Server 2008r2。

最佳答案

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

cd [foo%2ebar%2ecom_content]

关于sql - 如何使用来访问SQL Server数据库。通过设置位置的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25046957/

相关文章:

c# - 如何在 EF Core 中的Where子句中使用日期?

sql - 如何插入包含撇号(单引号)的值?

python - 从 pyodbc 插入 SQL Server 时出现 "Invalid object name"错误

sql-server - FROM 子句中的 CASE

azure - 使用 az powershell 创建 azure AD 应用程序

sql - 死锁谜题 : Victim doesn't own any resource, 用于杀掉解决死锁

mysql - 将行拆分为多行——联合的替代方法?

sql - SQL Server 和 mysql 上的增量备份

powershell - F5 BIG-IP Powershell/iControl - 查询节点级别的当前连接

powershell - Azure-SSMS-PowerShell