Hi,
I have a stored procedure "sp_TestBackupDatabase" and executing in powershell like below:
$query = "exec sp_TestBackupDatabase @dataBaseName=" + $dataBase + ", @backupType=" + $backupType + ", @backupFolder='" + $backupFolder + "'"
$emailContent += sqlcmd.exe -S serverame\SQLEXPRESS2014 -E -V 11 -d master -Q $query
$emailContent += "nLASTEXITCODE: $LASTEXITCODE
n`n"
When I directly execute the stored procedure, its working fine. But in powershell, I am getting exit code as 16 and error message says stored procedure "sp_TestBackupDatabase" could not be found.
Can anyone let me know what is wrong with command "sqlcmd.exe -S serverame\SQLEXPRESS2014 -E -V 11 -d master -Q $query" ?
I have recently reinstalled newer version of SQL server management studio and changed the path of power shell script.
Before these changes, this script was working fine.
I basically want to take back up of database and delete back ups older than two days. So any point of time I should have only two back ups.
This I want it to automate through task or any mechanism. If you have any better solution please let me know.
Kindly waiting for your response.
Thanks,
Santosh