2016-09-21 7 views
-4

Ich bin neu in C# und SQL Server; Ich schrieb eine einfache gespeicherte Prozedur in T-SQL, und in C# mit unter Coderuf dass:Wie kann Verbindungszeitfehler in C# gelöst werden?

da = new SqlDataAdapter("select_equals_Cycle", con); 
da.SelectCommand.CommandType = CommandType.StoredProcedure; 
ds = new DataSet(); 
da.Fill(ds, "select_equals_Cycle"); 

aber auf dieser Linie:

da.Fill(ds, "select_equals_Cycle"); 

ich diesen Fehler:

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

Meine Verbindungszeichenfolge folgendermaßen aus:

string conn = "Data Source=.;Initial Catalog=ClubEatc;Integrated Security=True;Connect Timeout=30;"; 

Wie kann ich das lösen? Vielen Dank.

+6

Sie müssen nicht verwendet, um die Ursache des Timeout zu finden. Liegt es daran, dass Sie versuchen, eine Milliarde Gigabyte aus der Datenbank zu laden? Wartest du auf ein Schloss? Hast du ein wirklich langsames Netzwerk? Hast du * ein * Netzwerk? Du kannst immer nur das Timeout erhöhen, aber es sei denn, du hast einen Überblick darüber, warum es nicht wirklich ein Fix ist, eher wie ein Bandaid. –

+0

Nun, wenn alles andere fehlschlägt, können Sie die Zeitüberschreitung in der Verbindungszeichenfolge erhöhen - wenn die Prozedur so lange läuft - wenn eine gespeicherte Prozedur mehr als 30 Sekunden zum Füllen eines Datensatzes ausführt, ist die Prozedur entweder ineffizient oder der Server ist nicht t eingerichtet für die benötigte Ladung. – Adwaenyth

+0

Versuchen Sie die Schritte in diesem Link http://stackoverflow.com/questions/8602395/timeout-expired-the-timeout-period-elapsed-prior-to-completion-of-the-operation –

Antwort

0

Verwendung Command oder optimieren die StoredProcedure

da.SelectCommand.CommandTimeout = 180; // default is 30 seconds 
0

Sie den Timeout-Wert nicht gesetzt ist, wenn Sie nicht wissen, wie sie konfigurieren.

Microsoft machen das optionale hat gut definierten Wert.

Die Timeout-Frage hat zwei Elemente, die Sie auschecken müssen.

Datenbank: z.B. MSSQL

--the code below ran in Query of Sql Server 
--this code snippet will show you all the advance options 
Exec sp_configure 'show advanced options',1 
recogfigure 
-- this code snippet configure the seconds of the query wait 
-- this configuration means that if the memory couldn't used to query -- the big query, sql server will wait for some seconds 
-- this option usually use the default value made by Microsoft 
-- the default value about how many seconds of formula is the estimated query -- -- time multiply by 25, and if the memory still couldn't used for querying. 
-- then throw TimeOut Exception 
Exec sp_configure 'query wait', 200; 
ReCONFIGURE 
-- the end 

// the timeout configuration about C# 
SqlConnection.ConnectionTimeout = 200 
// here is the Document: 
// get the time to wait while trying to establish a connection before 
// terminating the attempt and generating and error 
// the Unit of the property is second 
// 0 is no limit 

, nachdem Sie den Code-Schnipsel scannen, werden Sie zwei Grund finden die Ausnahme verursachen.

  1. Ihr Code konnte die Verbindung nicht herstellen.

  2. Ihr Gedächtnis in der Maschine SQL Server installieren könnte die große Abfrage auszuführen

Verwandte Themen