试图连接到服务器上的SQL Server 2008实例,我们将调用Sputnik。 两台设备之间没有防火墙。
现在我只想列出数据库
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-Null $servername = "Sputnik" $remoteServer = New-Object("Microsoft.SqlServer.Management.Smo.Server") $servername $remoteServer.databases
出现以下错误信息:
The following exception was thrown when trying to enumerate the collection: "Failed to connect to server Sputnik.". At line:1 char:15 + $remoteServer. <<<< databases + CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException + FullyQualifiedErrorId : ExceptionInGetEnumerator
有几点build议:由于您使用的是Windows身份validation,您的Windowslogin是否可以访问远程服务器,并且两台计算机都在同一个域上? 你能使用其他工具连接吗? 一个快速的方法是设置和ODBC连接:ODBC数据源>>添加SQL Server >>testing连接