環境:
Client : Win 2012 R2 安裝 SQL 2014 Feature Fack , 已安裝SQLPS
Server: SQL 2008 R2 , Instance 為預設安裝
需求:
要從Client 端遠端執行SQLPS ,備份Server 端資料庫
Code:
$server = 'X.X.X.X\MSSQLSERVER' #預設安裝
$db = 'test'
$username = 'sa'
$password = 'xxxxxxxxxx'
$password = ConvertTo-SecureString -AsPlainText $password -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$password
Backup-SqlDatabase -ServerInstance $server -Database $db -BackupFile "D:\test.bak" -Credential $cred
Problem
執行就會報錯:
Backup-SqlDatabase : 無法連接伺服器 X.X.X.X\MSSQLSERVER
D:\Source\backupSql.ps1:8 ??:1
+ Backup-SqlDatabase -ServerInstance $server -Database $db -BackupFile "D:\test.ba ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Backup-SqlDatabase], ConnectionFailureException
+ FullyQualifiedErrorId : Microsoft.SqlServer.Management.Common.ConnectionFailureException,Microsoft.SqlServer.Management.PowerShell.Backup SqlDatabaseCommand
請問有人知道問題在哪嗎 ?
謝謝^^