9

I am using Microsoft.SqlServer.Management.Smo.

My Code:

Server server = new Server(new ServerConnection( new SqlConnection(ConnectionString));
server.ConnectionContext.ExecuteNonQuery(script);

I want to set CommandTimeout for it like we do with normal SQLCommand

Please tell me how to set CommandTimeout for queries running through Microsoft.SqlServer.Management.Smo.Server

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178

3 Answers3

10

Try server.ConnectionContext.StatementTimeout

Rajesh
  • 7,766
  • 5
  • 22
  • 35
Strillo
  • 2,952
  • 13
  • 15
8

You can set command timeout using the SMO object as shown below:

Server server = new Server(new ServerConnection(new SqlConnection(ConnectionString));
server.ConnectionContext.StatementTimeout = 10800;
server.ConnectionContext.ExecuteNonQuery(script);

For more information on SMO object command timeout refer this link.

Rajesh
  • 7,766
  • 5
  • 22
  • 35
1

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx

how to set the query timeout from SQL connection string

Community
  • 1
  • 1
Tilak
  • 30,108
  • 19
  • 83
  • 131
  • i know how to set commandtimeout with sqlcommand.. but i don't know how to assign that command to Microsoft.SqlServer.Management.Smo.Server – Dr. Rajesh Rolen May 09 '12 at 08:34
  • did you try to set ConnectTimeOut in ServerConnection, http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.common.connectionsettings.connecttimeout.aspx – Tilak May 09 '12 at 08:41