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
  • 30,473
  • 11
  • 66
  • 95
Dr. Rajesh Rolen
  • 13,643
  • 39
  • 101
  • 175

3 Answers3

10

Try server.ConnectionContext.StatementTimeout

Rajesh
  • 7,551
  • 5
  • 20
  • 35
Strillo
  • 2,942
  • 12
  • 14
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,551
  • 5
  • 20
  • 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
  • 28,854
  • 17
  • 79
  • 129
  • 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