如何导致数据库超时异常?

发布于 2024-07-26 01:23:12 字数 139 浏览 2 评论 0原文

我需要测试一些处理 MS-SQL 数据库调用超时异常的 ASP.NET 代码。

我可以减少连接上的 CommandTimeout 参数,但这可能会在到达我的代码之前导致错误。

有没有一种简单的方法可以使数据库“按提示”超时?

I need to test some ASP.NET code that handles timeout exceptions from a call to a MS-SQL database.

I'm able to reduce my CommandTimeout parameter on the connection, however this might cause errors before reaching my code.

Is there a simple way to cause the database to timeout 'on cue'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

北城孤痞 2024-08-02 01:23:12

先生,您正在寻找的是 WAITFOR 命令,队列中的数据库超时每当你愿意的时候。

What you are looking for sir is the WAITFOR command, database timeouts on queue whenever you feel like it.

夏の忆 2024-08-02 01:23:12

在 Management Studio SQL 窗口中开始事务,更新表,但不提交它:

BEGIN TRAN
UPDATE table SET ...

这将锁定任何尝试读取该表的网站。

Begin a transaction in a management studio SQL window, update the table, and don't commit it:

BEGIN TRAN
UPDATE table SET ...

This will lock any website attempt to read that table.

复古式 2024-08-02 01:23:12

难道你不能在你想要测试的任何 try 块中抛出你想要的异常吗?

Couldn't you just throw the exception that you want in whatever try block you want to test?

桜花祭 2024-08-02 01:23:12

编写一个在每次迭代中循环执行一些复杂任务的过程......如果这还不够,可以通过递归调用存储过程进一步扩展它!

Write a procedure that loops for ever doing some complex task with each iteration...and if that is not enough further expand it by calling the stored procedure recursively!

榕城若虚 2024-08-02 01:23:12

我通过拔掉以太网线来便宜这个,哈哈......

Ive cheaped this by unplugging my ethernet cable lol...

夏末 2024-08-02 01:23:12

开始测试,然后关闭数据库服务器(sc stop“MSSQL$SQLEXPRESS”或其他内容)。

Begin your test, then turn off your database server (sc stop "MSSQL$SQLEXPRESS" or something).

时间你老了 2024-08-02 01:23:12

您可以考虑用 mock 替换数据库连接,这可以简化您的测试。

在这种情况下,模拟总是会发出超时信号。

You might consider replacing the DB connection with a mock, that could simplify your testing.

In this case, the mock would simply always signal a timeout.

独自唱情﹋歌 2024-08-02 01:23:12

写下执行时间超过 30 秒的过程或查询,并
从 ASP.NET 代码中调用它。

write down the procedure or Query which take more than 30 seconds to execute and
call this from asp.net code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文