简体   繁体   English

如何使用来访问SQL Server数据库。 通过设置位置命名

[英]How can I access a SQL Server database with . in name via set-location

Question is in the title. 问题在标题中。 I have a database server which has a number of databases that have periods in the name (they are urls so that I know which database is associated with which site such as foo.bar.com_content). 我有一个数据库服务器,该服务器具有多个名称中带有句点的数据库(它们是url,以便我知道哪个数据库与哪个站点关联,例如foo.bar.com_content)。 When I navigate to SQLSERVER:\\sql\\[server]\\default\\databases and run get-childitem I can see a list of all my databases just fine. 当我导航到SQLSERVER:\\sql\\[server]\\default\\databases并运行get-childitem我可以看到所有数据库的列表。 When I try to cd [database name with period] I get the following error: 当我尝试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

That error repeats four times, followed by: 该错误重复四次,然后执行以下操作:

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

I can run the same command to a database on the same server that has no periods in the name and connect just fine. 我可以在同一服务器上的名称中没有句号的数据库上运行同一命令,并且连接正常。

I am running this from my windows desktop machine in the Powershell ISE, Powershell v2.0 with the SQL Server 2012 tools installed. 我正在Powershell ISE的Windows台式机上运行此程序,安装了SQL Server 2012工具的Powershell v2.0。 The remote database server is running SQL Server 2008r2. 远程数据库服务器正在运行SQL Server 2008r2。

Try Changing the period . 尝试更改期限. to it's hex value of %2e like below, considering that the database name is foo.bar.com_content . 假设数据库名称为foo.bar.com_content则为十六进制值%2e如下所示。

cd [foo%2ebar%2ecom_content]

Rahul's answer is generally correct but remove the brackets. 拉胡尔的答案通常是正确的,但要删除括号。 Here is a correction to Rahul's answer. 这是对拉胡尔答案的更正。

cd foo%2ebar%2ecom_content

If your name convention utilizes spaces then encase it in quotes (single or double either works) 如果您的名称约定使用空格,则将其用引号引起来(单选或双选均可)

cd 'foo%2eb ar%2ecom_content'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM