如何设置CommandTimeout

9

我是使用 Microsoft.SqlServer.Management.Smo

我的代码:

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

我希望能够像普通的SQLCommand一样为其设置CommandTimeout

请告诉我如何为通过Microsoft.SqlServer.Management.Smo.Server运行的查询设置CommandTimeout

3个回答


8
您可以使用下面显示的SMO对象设置命令超时时间:

使用SMO对象,您可以设置命令超时时间,如下所示:

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

有关SMO对象命令超时的更多信息,请参阅此链接


1

我知道如何使用sqlcommand设置commandtimeout,但是不知道如何将该命令分配给Microsoft.SqlServer.Management.Smo.Server。 - Dr. Rajesh Rolen
你尝试在ServerConnection中设置ConnectTimeOut吗?参考链接:http://msdn.microsoft.com/zh-cn/library/microsoft.sqlserver.management.common.connectionsettings.connecttimeout.aspx - Tilak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接