SQLBackupC - Mailto
aarons44
Posts: 32
I was wondering what settings SQLBackupC uses for sending mail with the mailto option? Does it use the settings specified in the GUI, or do you need to specify the mail server in the command?
Comments
One difference when using the command line interface is that all the work will be performed using the credentials of the logged-on user. When using the extended stored procedure, all work is performed using the credentials of the SQL Backup service startup user.
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8
Thanks!
query10 = "-SQL ""RESTORE DATABASE " & myString6 & " FROM DISK = 'G:\myFiles\CompressedBackups" & myFile6 & "' WITH MOVE '" & myString6 & "' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" & myString6 & ".mdf', MOVE '" & myString6 & "_LOG' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" & myString6 & ".ldf' WITH MAILTO='myemail@mydomain.com'"" -I sql -U user -P password THREADPRIORITY=6"
The problem must be with where the mailto option is placed, because the restore works. Here I get a syntax error. I've also tried putting it right before the -I and I don't get an error, but I don't get the mail either. Test emails from the GUI work fine. The mail server doesn't require authentication, so credentials shouldn't be an issue.
The generated command will not function correctly because of confusion between the various tags.
Any part of the SQL Backup command needs to go inside the -SQL "..." tag, and the -I, -U and -P tags come afterwards.
So in your example, this should be:
query10 = "-SQL ""RESTORE DATABASE " & myString6 & " FROM DISK = 'G:\myFiles\CompressedBackups\" & myFile6 & "' WITH MOVE '" & myString6 & "' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" & myString6 & ".mdf', MOVE '" & myString6 & "_LOG' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" & myString6 & ".ldf' WITH MAILTO='myemail@mydomain.com', THREADPRIORITY=6"" -I sql -U user -P password "
Hope that helps,
Jason
query10 = "-SQL ""RESTORE DATABASE " & myString6 & " FROM DISK = 'G:\myFiles\CompressedBackups" & myFile6 & "' WITH MOVE '" & myString6 & "' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" & myString6 & ".mdf', MOVE '" & myString6 & "_LOG' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" & myString6 & ".ldf', MAILTO='myemail@mydomain.com', THREADPRIORITY=6 "" -I sql -U user -P password "
The comma before the MAILTO was needed to make it a continuation of the previous WITH statement. Thanks for your help. It was really confusing getting the single quotes, double quotes, two sets of double quotes, etc. all figured out to make this work.
Not sure what version of VB you are using, but if you are using .NET, you could use the String.Format function to try and make the code easier to understand (if you have to do this again in the future):
For example, your code would become something like:
query10 = String.Format(@ -SQL "RESTORE DATABASE {0} FROM DISK = 'G:\myFiles\CompressedBackups\{1}' WITH MOVE '{0}' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\{0}.mdf', MOVE '{0}_LOG' TO 'G:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\{0}.ldf', MAILTO='myemail@mydomain.com', THREADPRIORITY=6 "" -I sql -U user -P password",myString6,myFile6);
Granted it's still not ideal, but it's eliminated a significant number of the double quotes... so seems slightly less complicated. The following link may be useful (mentions C#, but should be the same in VB.net): http://blog.stevex.net/index.php/string ... in-csharp/
Hope that helps,
Jason