クエリのタイムアウトをテストする方法
SQLの実行に、設定した時間以上かかった場合、エラーとなる処理をテストする方法。
ADOで言えば、ConnectionオブジェクトのCommandTimeout値を超えるようにするには、どんなクエリを実行すれば良いか?というお話。
CommandTimeout のエラーハンドリングをテストしたくて検索していたら、次の構文を発見しました。
WAITFOR { DELAY 'time_to_pass' | TIME 'time_to_execute' | [ ( receive_statement ) | ( get_conversation_group_statement ) ] [ , TIMEOUT timeout ] }
例:30秒たったら返ってくるSQL
WAITFOR DELAY '00:00:30'
例:timeout するASP
<% Option Explicit Dim ConStr ' Connection String Dim objCon ' Instance of ADO Connection Dim strSQL ' SQL ConStr = "" Set objCon = Server.CreateObject("ADODB.Connection") objCon.CommandTimeout = 10 ' Default 30[s] objCon.Open ConStr strSQL = "WAITFOR DELAY '00:00:40'" objCon.Execute strSQL ' Rize timeout error objCon.Close Set objCon = Nothing %>