2014-04-04 57 views
-1

工作是什麼SQL INSERT查詢現在工作一週也不會在所有

--------------------------- 

--------------------------- 
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.) 
--------------------------- 
OK 
--------------------------- 

,實際上意味着什麼呢?

我認爲,「事情花了太長時間,所以我放棄了。」

我不明白爲什麼會出現超時,因爲我將超時設置爲4分鐘,並且此錯誤在不到30秒的時間內彈出。

爲什麼這個確切的代碼在過去的一週工作,現在它只是失敗了每一次?

我試過設置cmd.CommandTimeout = 240這是一個很長的時間來等待調試時,和同樣的問題。數據庫中沒有任何更新。我不明白髮生了什麼變化。

try 
    { 
     // Insert into database 
     sqlconnection = new SqlConnection(@"Data Source=s1-removed-om;Initial Catalog=D-removed-t;Persist Security Info=True;User ID=D-removed-;Password=97-removed3-45;"); 

     sqlconnection.Open(); 

     cmd = new SqlCommand(); 
     cmd.Connection = sqlconnection; 

     int count = 0; 

     foreach (var item in files) 
     { 
      cmd.CommandText = @"insert into Images (Name, Credits) values ('" + item.Value + "', '" + credits + "')"; 
      cmd.ExecuteNonQuery(); 

      count++; 
     } 

     doneUpdatingDB = true; 
    } 
    catch (Exception exception) 
    { 
     MessageBox.Show(exception.Message); 
     doneUpdatingDB = false; 
    } 
+0

您可以看看:http://stackoverflow.com/questions/3270199/a-connection-was-successfully-established-with-the-server-but-then-an-error-occ – Jivan

回答

1

你使用的是什麼框架?

試試這個:

1. Restart Visual Studio. 
2. Re-build project. 
3. Re-install latest .NET Framework. 

檢查this

+0

感謝您的回答。我安裝了最新的框架。 4.5.1但是我的項目只是針對客戶需求4.5。 – uSeRnAmEhAhAhAhAhA

2

這不是命令超時,您在這裏遇到連接超時。這意味着您的客戶端無法及時向SQL Server進行身份驗證(默認時間爲30秒)。 增加連接超時。如果這沒有幫助,請重新啓動本地計算機。如果這沒有幫助,請通知服務器管理員有關該問題。

+0

謝謝院長。他們可以設置超時時間少於30秒嗎?我問這是因爲錯誤發生在30秒內。通常約20-25秒。 – uSeRnAmEhAhAhAhAhA

+1

這是一個客戶端設置:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx – dean

+0

謝謝院長! :-) – uSeRnAmEhAhAhAhAhA