编辑 1:我能够通过 Windows PowerShell ISE 但不是 PowerGUI 成功创建复制对象。该脚本曾经在我的 32 位机器上成功运行,现在在我的 64 位机器上运行出错。问题看起来是环境问题。
我正在尝试使用来自 powershell 的 SQL 身份验证连接到我的分发 SQL Server 实例并创建一个复制对象。我无法使用 Windows 身份验证测试连接。
以下代码源自http://sqlpsx.codeplex.com/和加载的模块 Repl (Repl.psm1)。
$sqlServer = "SQL Server"
$Username = "UserName"
$Password = "Password"
[Microsoft.SqlServer.Management.Common.ServerConnection]$con = Get-SqlConnection $sqlServer $username $password
Write-host "Get-ReplServer $($con.ServerInstance)"
$repl = new-object ("Microsoft.SqlServer.Replication.ReplicationServer") $con
或更具体地说
new-object ("Microsoft.SqlServer.Replication.ReplicationServer") $con
生成以下错误
New-Object : Cannot find an overload for "ReplicationServer" and the argument count: "1".
At line:25 char:19
+ $repl = new-object <<<< ("Microsoft.SqlServer.Replication.ReplicationServer") $con
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
服务器连接代码
[Microsoft.SqlServer.Management.Common.ServerConnection]$con = Get-SqlConnection $sqlServer $username $password
成功完成并返回正确的服务器信息
SQL 服务器版本是
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
Jun 28 2012 08:36:30
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: ) (Hypervisor)
和 PowerShell 版本
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
我的问题似乎 与使用 sql authentication 连接到 ReplicationServer的问题相同。然而,乍得米勒的解决方案并没有解决我的问题,即
$con.Connect()
$repl = new-object ("Microsoft.SqlServer.Replication.ReplicationServer") $con
任何理想将不胜感激。