EDIT : Problem with the email I get mailbox unavailable exception! DBEmail.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Xml.Linq;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure()]
public static void DBEmail(string Sender, string SendTo, string Subject, string Body, string mailServer)
{
System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
m.From = new System.Net.Mail.MailAddress(Sender);
m.To.Add(new System.Net.Mail.MailAddress(SendTo));
m.Subject = Subject;
m.Body = Body;
System.Net.Mail.SmtpClient client = null;
client = new System.Net.Mail.SmtpClient();
client.Host = mailServer;
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
client.Send(m);
}
}
I have to run some nightly stored procedures. So I have created a .sql file which has basically -
exec proc1
exec proc2...
So is it fine if i just run them like that or they need to wrapped in begin end or something else... Fruther I have a batch file which i will schedule to run-
sqlcmd -S myserver.myserver.com -i
D:\Scripts\StartProcs.sql -U username -P password -o D:\Scripts\log.txt
Is this the above script correct ? I mean it works it tested running it...but i just need to make sure if i am not missing any other issues here ? Because I saw some other sqlcmd commands which where really long and took lot of parameters...I just want to make sure i am not missing any important parameters..
Please correct me above with either .sql file or batch file...if i have not taken in consideration any issues? ...Thanks