I am writing C # code and using LINQ and some stored procedures, I have to open and close the connection But I keep this error in mind.
Timeout expired. The expiration time has expired to get a connection from the pool. This can happen because all pool connections were in use and reached the maximum pool size. My code works entirely except in the event of this error, what can I do about it?
Thanks for any thoughts.
public static list & lt; Int & gt; GetIslemIdleribySPbyCariId (int cariId) {string connString = System.Configuration.ConfigurationManager.ConnectionStrings ["LocalSqlServer1"]. ConnectionString; SqlConnection sqlConn = New SqlConnection (connString); SqlConn.Open (); & Lt; Integer & gt; Islemidleri = new list & lt; Int & gt; (); Islemidler.Clear (); SqlCommand CMD; CMD = New SQL Commands ("Gate islam idleri", SKL cone); Cmd.CommandType = CommandType.StoredProcedure; Cmd.Parameters.Add (new SqlParameter ("@ CARIID", cariId)); (Reader.Read ()) when using (Var reader = cmd.ExecuteReader ()) {islemidleri.Add (reader.GetInt32 (0)); } Cmd.Parameters.Clear (); } SqlConn.Close (); Return isylmillery; } /// & lt; Summary & gt; /// SP Kollanarak Dovgturlini Dindand ¼ RAIR /// & LT; / Summary & gt; /// & lt; Returns & gt; String List Dindayd ¼ RAIR IACIN DOVS TARRLLY YR TL, USS Vs & lt; / Returns & gt; Public static list & lt; String & gt; GetDovizTurleribySP () {string connString = System.Configuration.ConfigurationManager.ConnectionStrings ["LocalSqlServer1"]. ConnectionString; SqlConnection sqlConn = New SqlConnection (connString); SqlConn.Open (); & Lt; String & gt; DovizTanimlari = New list & lt; String & gt; (); String command gatewaywikiinlinelery = "excise gateway tannymery"; SqlCommand CMD; CMD = new SQL Commands (CommandGettoVizTanimalary, SKL Con); (Reader.Read ()) when using (Var reader = cmd.ExecuteReader ()) {dovizTanimlari.Add (reader.GetString (0)); }} Return dovishtinillery; }
From your code you suggest that GetDovizTurleribySP function You can use the statement using to ensure that the connections are closed even when an exception occurs. Something like this can look like
public static list & lt; String & gt; GetDovizTurleribySP () {string connString = System.Configuration.ConfigurationManager.ConnectionStrings ["LocalSqlServer1"]. ConnectionString; (Using SqlConnection sqlConn = New SqlConnection (connString)) {sqlConn.Open (); & Lt; String & gt; DovizTanimlari = New list & lt; String & gt; (); String command gatewaywikiinlinelery = "excise gateway tannymery"; SqlCommand CMD; CMD = new SQL Commands (CommandGettoVizTanimalary, SKL Con); (Reader.Read ()) when using (Var reader = cmd.ExecuteReader ()) {dovizTanimlari.Add (reader.GetString (0)); }} Return dovishtinillery; }}
Comments
Post a Comment