Groups | Blog | Home
all groups > sql server programming > may 2006 >

sql server programming : SQL Backup using SMO: Timeout 600s


Dan Guzman
5/6/2006 5:03:46 PM
You can specify the desired StatementTimeout property of the
Server.ConnectionContext:

svr.ConnectionContext.StatementTimeout = 3600; //1 hour timeout

--
Hope this helps.


Dan Guzman
SQL Server MVP

[quoted text, click to view]

Håkan
5/6/2006 10:39:19 PM
Hi!

I am trying to backup all databases from a SQL 2005 Express server. One of
the databases is rather large and while backing up it I receive a time out
after 600 s (10 minutes).
I can't find any where to set the time out for the backup command.

So, How do I set the timeout that SMO uses for it's commands to the server
its databases?


Here is the code I am using

Server svr = new Server(new ServerConnection("localhost"));
Backup bkp = new Backup();
bkp.Action = BackupActionType.Database;

foreach(Database db in svr.Databases)
{
if(db.Name == "tempdb")
continue;

if(!Directory.Exists(BackupPath + db.Name))
{
Directory.CreateDirectory(BackupPath + db.Name);
}
DateTime dat = DateTime.Now;

bkp.Database = db.Name;

bkp.Devices.Clear();
bkp.Devices.Add( new BackupDeviceItem( BackupPath + db.Name + @"\" +
dat.ToString("yyyy-MM-dd_HH-mm-ss") + "_" + db.Name + ".bkp",
DeviceType.File));

bkp.SqlBackup(svr); //<== This is where the timeout occur
}

AddThis Social Bookmark Button