DECLARE @path VARCHAR (500) /* Path of the Backup Files */
DECLARE @folderdate VARCHAR (75) /* The subdir for my backups with Format YYYYMMDD */
DECLARE @cmd VARCHAR (4000) /* The command to create Subdir */
DECLARE @DBName varchar(255)
DECLARE @DATABASES_Fetch int
DECLARE @PreciceDateTime varchar(255)
DECLARE @ServerName varchar(50)
DECLARE @NetworkBackupShare varchar(75)
--Network or local disk path you wish to use, such as D:\Backup
SET @NetworkBackupShare = N'C:\backup'
--Create a dynamic path for the backup of the databases based on datetime
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
/* gives us YYYYMMDD
hour hh
minute mi, n
second ss, s
*/
--PRINT @folderdate
SET @ServerName = (SELECT @@servername)
/* Path as C:\Backup\YYYYMMDD */
SET @path =''
/* Create the command that will do the creation of the folder*/
SET @cmd = N'mkdir ' + @path
--PRINT @cmd
/* Create the new directory */
EXEC master.dbo.xp_cmdshell @cmd , no_output
/* now I can direct all the backup file to the created subdirectory like,
SET filename = path [other_variable/s] ‘.BAK‘ */
/*******************************************/
--Now let's actually do the backups to the path created above
DECLARE DATABASES_CURSOR CURSOR FOR
select
DATABASE_NAME = db_name(s_mf.database_id)
from
sys.master_files s_mf
where
-- ONLINE
-- s_mf.state = 0
-- Only look at databases to which we have access
has_dbaccess(db_name(s_mf.database_id)) = 1
-- Not master, tempdb or model
and db_name(s_mf.database_id) not in ('Master','tempdb','model')
group by s_mf.database_id
order by 1
OPEN DATABASES_CURSOR
FETCH NEXT FROM DATABASES_CURSOR INTO @DBName
WHILE @@FETCH_STATUS = 0
BEGIN
declare @DBFileName varchar(256)
set @DBFileName = --datename(dw, getdate()) + ' - ' +
replace(replace(@DBName,':','_'),'\','_') + '.BAK'
PRINT @path
exec ('BACKUP DATABASE [' + @DBName + '] TO DISK = ''' + @path +
@DBFileName + ''' WITH NOFORMAT, INIT, NAME = N''' +
@DBName + '-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD, STATS = 100')
FETCH NEXT FROM DATABASES_CURSOR INTO @DBName
END
CLOSE DATABASES_CURSOR
DEALLOCATE DATABASES_CURSOR
Monday, June 28, 2010
Backup Of All Database of SQL which are attached
Thursday, June 24, 2010
Changing the tab index of AJAX Tab control through Javascript
function SetActiveTab(tabControl, tabNumber)
{
var ctrl = $find(tabControl);
ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);
}
Here
1.tabControl is client id of tabcontainer.
2.tabNumber is tab index as numeric
to pass Client ID use this
<input type="Button" onClick="SetActiveTab('<%=tabControl.ClientID%>',2);"
value="Next"> </input>
Wednesday, June 23, 2010
Sending E-mail with uploaded attachment
protected void Btn_Send_Click(object sender, EventArgs e)
{
try
{
string to =Txt_To.Text;
string[] str = to.Split(';');
string from = Txt_From.Text;
string from_pwd = "12345678";
MailMessage mM = new MailMessage();
mM.From = new MailAddress(from);
foreach (string s in str)
{
mM.To.Add(s);
}
mM.Subject = Txt_Subject.Text;
mM.Body = Txt_message.Text;
mM.IsBodyHtml = true;
string s1 = "";
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("mail.kumbhaj.com");
sC.UseDefaultCredentials = false;
sC.Port = 25;
if (FileUpload1.HasFile)
{
FileInfo f = new FileInfo(FileUpload1.FileName.ToString());
s1 = Guid.NewGuid().ToString();
s1 = "uploadfile/" + s1 + f.Extension;
FileUpload1.SaveAs(Server.MapPath(s1));
Attachment at = new Attachment(Server.MapPath(s1));
mM.Attachments.Add(at);
}
sC.Credentials = new System.Net.NetworkCredential(from, from_pwd);
sC.EnableSsl = false;
sC.Send(mM);
Lbl_Failled_Report.Text = "Message Successfully send.";
}
catch (Exception ex)
{
Lbl_Failled_Report.Text = "Message sending Failled!";
}
}
Tuesday, June 22, 2010
To Add Column Through Stored Procedure.
For Sending Email Through C#
using System;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace TestingConsole
{
class Program
{
static void Main(string[] args)
{
try
{
string to = "to@domain.com";
string from = "from@gmail.com";
string from_pwd = "mypassword";
string subject = "Sample Mail testing";
string body = "Wow this is testing body";
MailMessage mM = new MailMessage();
mM.From = new MailAddress(from);
mM.To.Add(to);
mM.Subject = subject;
mM.Body = body;
mM.IsBodyHtml = false;
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
sC.Port = 587;
sC.Credentials = new NetworkCredential(from,
from_pwd);
sC.EnableSsl = true;
sC.Send(mM);
}
catch (Exception e)
{
Console.WriteLine(e.Message + " " + e.StackTrace);
}
}
}
}
You can use in window or web application accordig to you need.
Subscribe to:
Posts (Atom)