Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

How to set CommandTimeout

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

Upvotes: 9

Views: 16883

Answers (3)

Rajesh
Rajesh

Reputation: 7876

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.

Upvotes: 8

Strillo
Strillo

Reputation: 2972

Try server.ConnectionContext.StatementTimeout

Upvotes: 10

Related Questions