【解決済み】SSMSでのタイムアウトエラー「Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.」

Web技術

結論

SSMS(SQL Server Management Studio)タイムアウトが起きたら、以下の3つをやってみる。自分の場合は、最後の3番で解決された。

  1. クエリ実行のタイムアウト設定
  2. コネクションのタイムアウト設定
  3. テーブルの「デザイン (Design)」からGUIで変更するのではなく、SQLを書いて実行する。

現象

SSMS(SQL Server Management Studio)を用いてテーブルに対して操作をした時に、以下のタイムアウトエラーが発生しました。

Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

SQL Server Management Studioで出たエラー

エラーが発生したタイミングは、テーブルのカラムに対して、indexを付与しようとしたときです。

SQLを書くのがめんどくさかったので、テーブルのDesignから、GUIでインデクスを付けようとしました。

(既に多くのデータが格納されているテーブルに対してクラスター化されたindexを付けようとしたため、時間がかかることは想定される処理です。)

時間がかかることは避けられない処理のため、SSMS側の設定を変えて、タイムアウトしないようにする必要があると考えて、調べました。

対処

少しググってみてすぐに出てくるのは、以下の対処でした。

Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. - Microsoft Q&A
Hi Team, We are getting below error while running query in SSMS: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation...

By default, SSMS waits forever for a query to complete. If you get this error, this is because you have set a query timeout under Tools->Options->Query Execution->SQL Server->General->Execution time-out. You can also change it for the current window, by right-clicking and selecting Query Options from the bottom of the context menu. Set the time-out to 0 to wait forever.

https://docs.microsoft.com/en-us/answers/questions/466818/execution-timeout-expired-the-timeout-period-elaps.html

SSMSの「Tools->Options->Query Execution->SQL Server->General->Execution time-out」から設定を変えられるようです。

ただ、自分の場合、この設定は最初から「0」、つまり、「無限に待つ」状態でした。

僕の状態

「え?じゃあなんでタイムアウトしてんの?」

と思いましたが、クエリの実行自体のタイムアウトとは別に、DBとのコネクションのタイムアウト時間を別に設定しなきゃいけないんですね。

それに関しては、以下のサイトが参考になりました。

SQL SERVER - Timeout expired. The timeout period elapsed prior to completion of the operation - SQL Authority with Pinal Dave
Today we are going to learn about how to fix the error: Timeout expired. The timeout period elapsed prior to the completion of the operation.

まず、SSMSを一旦閉じて開きなおすか、Server nameを右クリックしてConnectを押下する。

Optionsを押す。

Optionsを押す

Connection time-outが設定できるので、「0」にする。

Connection time-outが30秒だった…

設定変えたら「Connect」する。

この状態で再実行すると…!

この画像には alt 属性が指定されていません
同じエラー…

同じタイムアウトエラーが出ました…(^^;)

GUIからやってるのが悪いのじゃないだろうか… とちょっぴり思い、以下のSQLを実行してみました。

CREATE CLUSTERED INDEX IX_ClientOpeLog_time
ON [dbo].[ZAppsClientOpeLog] (time);

ZAppsClientOpeLogはテーブル名、timeはカラム名、IX_ClientOpeLog_timeは今回作るindexの名前です。

実行すると…

成功した…

DesignからGUIでやると、別のタイムアウト設定が参照されるのかな…

Designから実行したときのタイムアウト時間を変更する方法もありそうだけど、SQL実行すればいけるなら、まぁ良いか。

この記事が同じ状況になった方の助けになれば幸いです。

コメント

タイトルとURLをコピーしました