الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مامعني هذا الخطأ ؟ وكيف يمكن معالجته ؟

بدأه ماكسيموس في 3 فبراير 2009 · 12 رد · 1,596 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا الخطأ مامعناه ؟

وكيف يمكن معالجته

مع العلم اني عندما اقوم بقراءة بيانات من قاعدة البيانات مثل تسجيل دخول مستخدم

يظهر هذا الخطأ ..؟

ما الحل في ذلك

والخطأ كالتالي :

Server Error in '/' Application.
--------------------------------------------------------------------------------

Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.

Source Error: 


Line 612:		catch (Exception)
Line 613:		{
Line 614:			throw;
Line 615:		}
Line 616:


Source File: c:\Inetpub\wwwroot\App_Code\DataProvider.cs	Line: 614 

Stack Trace: 


[InvalidOperationException: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.]
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +1261381
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.SqlClient.SqlConnection.Open() +111
   DataProvider.AdminLogin(String name, String pass) in c:\Inetpub\wwwroot\App_Code\DataProvider.cs:614
   LoginAdmin.Button1_Click1(Object sender, EventArgs e) in c:\Inetpub\wwwroot\LoginAdmin.aspx.cs:29
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBa
ckEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
#2

السلام عليكم ورحمة الله

بشكل مبسط لمعنى الخطأ ان هناك الكثير من الاتصالات مفتوحة وموضوعة في مكان يسمى pool لاعادة استخدامها مرة اخرى عند طلب نفس الاتصال

او ان العدد المسموح به في pool صغير .

لحل المشكلة اولا تأكد ان بيانات الاتصال صحيحة

ثانيا استخدم نفس بيانات الاتصال في مشروعك يعني نفس Connection String

ثالثا اغلق الاتصال بعد الانتهاء منه

رابعا جرب وضع Max Pool Size=100 في وصف الاتصال Connection String

#3

جزاك الله خير على هذا الرد

ولكن جميع ما ذكرته من نقاط قمت بتطبيقه

ماعدا الخطوة الاخيرة

وهذه بعض من الصفحة الخاصة بالاتصال مع قاعدة البيانات

مع العلم ان فيها اكثر من 20 الى 50 Method

جميعها تقوم بالاضافة او الاستعلام او التعديل

والكود كالتالي :

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


/// <summary>
/// Summary description for DataProvider1
/// </summary>
public class DataProvider
{
	public DataProvider()
	{
		//
		// TODO: Add constructor logic here
		//
	}

	private string _ConnectionString = ConfigurationManager.ConnectionStrings["kacstConnectionString"].ConnectionString;
	private string _ConnectionString2 = ConfigurationManager.ConnectionStrings["ROSConnectionString"].ConnectionString;




	public string ConnectionString
	{
		get { return _ConnectionString; }
		set { _ConnectionString = value; }
	}

	public string ConnectionString2
	{
		get { return _ConnectionString2; }
		set { _ConnectionString2 = value; }
	}


	//********************************************************************************
*********************************************
	public SqlDataReader ReadAllProgrammNames()
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString);
		SqlCommand myCommand = new SqlCommand("select * from programs_def", myConnection);
		myCommand.CommandType = CommandType.Text;

		try
		{
			myConnection.Open();
			return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch (Exception)
		{
			throw;
		}
	}

	//********************************************************************************
*********************************************
	public SqlDataReader ReadName(string program,string projyaer,string project)
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString);
		SqlCommand myCommand = new SqlCommand("SELECT aname = ( SELECT aname  FROM   manpower m where m.person# = h.picode ), picode FROM projects h WHERE PROGRAM# = '" + program + "' and projyear = '" + projyaer + "' and project# = '" + project + "'", myConnection);
		myCommand.CommandType = CommandType.Text;

		try
		{
			myConnection.Open();
			return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch (Exception)
		{
			throw;
		}
	}

	//********************************************************************************
*********************************************
	public SqlDataReader ReadAllYearSupport()
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString);
		SqlCommand myCommand = new SqlCommand("select * from yearsupport", myConnection);
		myCommand.CommandType = CommandType.Text;

		try
		{
			myConnection.Open();
			return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch (Exception)
		{
			throw;
		}
	}

	//********************************************************************************
*********************************************
	public SqlDataReader InsertInformationSupport(string ProjNumber1, string ProjNumber2, string ProjNumber3, string Picode, string SupportRequestDate, string SupportAccessDate, string SupportAmount, string CheckNumber, int YearSupportID, string WayDeposit)
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString);
		SqlCommand myCommand = new SqlCommand("INSERT INTO [dbo].[Deposit] ([ProjNumber1], [ProjNumber2], [ProjNumber3], [Picode], [SupportRequestDate], [SupportAccessDate], [SupportAmount], [CheckNumber], [YearSupportID], [WayDeposit] )VALUES ('" + ProjNumber1 + "','" + ProjNumber2 + "','" + ProjNumber3 + "','" + Picode + "','" + SupportRequestDate + "','" + SupportAccessDate + "','" + SupportAmount + "','" + CheckNumber + "'," + YearSupportID + ",'" + WayDeposit + "')", myConnection);
		myCommand.CommandType = CommandType.Text;

		try
		{
			myConnection.Open();
			return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch (Exception)
		{
			throw;
		}
	}




	//********************************************************************************
*********************************************
	public DataSet GetUserInfoByName(string Name)
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString2);
		SqlCommand myCommand = new SqlCommand("SELECT * FROM Experts1 where AName like '%"+ Name +"%'", myConnection);

		myCommand.CommandType = CommandType.Text;

		//SELECT * FROM Experts1 where AName like '%d%'
		SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
		try
		{
			DataSet dataSet = new DataSet();
			myAdapter.Fill(dataSet, "SELECT * FROM Experts1 where AName='"+ Name +"'");
			return dataSet;
		}
		catch (Exception)
		{
			throw;
		}
	}
#4

ما الحل ...؟

#5

اين ال Connection string ؟

#6

الـConnection String موجود في ملف web.config

وفي الصفحة هذه يتم استدعاءه وتطبيق الاتصال وهي بإسم DataProvider

والكود في الصفحة السابقة كالتالي :

	private string _ConnectionString = ConfigurationManager.ConnectionStrings["kacstConnectionString"].ConnectionString;
	private string _ConnectionString2 = ConfigurationManager.ConnectionStrings["ROSConnectionString"].ConnectionString;

	public string ConnectionString
	{
		get { return _ConnectionString; }
		set { _ConnectionString = value; }
	}

	public string ConnectionString2
	{
		get { return _ConnectionString2; }
		set { _ConnectionString2 = value; }
	}

ولكن هل الحل يمكن في اغلاق اي اتصال اقوم به بقاعدة البيانات

واعني عندما انشئ اتصال ومن ثم اقوم بالاستعلام فهل يجب اغلاق هذا الاتصال

ولكن هل الطريقة هذه تصلح بما انني استخدم method في عمليات الاتصال

	public SqlDataReader ReadAllProgrammNames()
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString);
		SqlCommand myCommand = new SqlCommand("select * from programs_def", myConnection);
		myCommand.CommandType = CommandType.Text;

		try
		{
			myConnection.Open();
			return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
			myConnection.Close();//close Connection

		}
		catch (Exception)
		{
			throw;
		}
	}

تم تعديل هذه المشاركة بواسطة ماكسيموس في 4 فبراير 2009 في 08:17

#7

السلام عليكم ورحمة الله

اولا انظر الى هذه المقالة http://msdn.microsoft.com/en-us/library/8xx3tyca(VS.80).aspx

ثانيا هل انت تعمل على نفس الجهاز وهل تظهر هذه المشكلة من اول تشغيل ام بعد فترة من العمل

وبالنسبة لاغلاق الاتصال فيجب عليك اغلاق بعد الانتهاء منه فمثلا العبارة myCommand.ExecuteReader(CommandBehavior.CloseConnection)

هذه تقوم بالاغلاق مباشرة وتلقائيا لكن عند استخدام Dataset لايتم الاغلاق مباشرة فعليك بالقيام بالاغلاق

ويفضل ايضا استخدام using

#8

بالنسبة للعمل على الجهاز

فانا لا اعمل على الجهاز الموجود عليه المشروع

فالمشروع موجود على سيرفر وانا اعمل عليه من سيرفر آخر

بالنسبة للخطأ . فهو لا يظهر لي دائماً

ففي بعض الاحيان يعمل المشروع جيدا ولكن في بعض الاحيان يعطي هذه الخطا وهذه الرسالة

وبالنسبة لأغلاق الاتصال فهل تعني ان هذا الكود صحيح وهو اني اقوم باغلاق

الاتصال عند الانتهاء من Method

والمشكلة تكمن في DataSet ولهذا فيجب علي اغلاق الاتصال في جميع DataSet's

ومثال هذا فلدي Method تقوم بهذا الامر ولكن لم اضع فيها الاقفال

والكود كالتالي :

	public DataSet GetUserInfoByName(string Name)
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString2);
		SqlCommand myCommand = new SqlCommand("SELECT * FROM Experts1 where AName like '%"+ Name +"%'", myConnection);

		myCommand.CommandType = CommandType.Text;

		//SELECT * FROM Experts1 where AName like '%d%'
		SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
		try
		{
			DataSet dataSet = new DataSet();
			myAdapter.Fill(dataSet, "SELECT * FROM Experts1 where AName='"+ Name +"'");
			return dataSet;
		}
		catch (Exception)
		{
			throw;
		}
	}

فلابد من قطع الاتصال هنا لكي لا يظهر الخطا باستعمال

myConnection.Close();

ولن يوجد لدي ملاحظة . لقد قمت باستعمال الطريقة نفسها بدون ايه اغلاقات

والى الان المشروع يعمل وهو اكبر مما اعمل عليه حالياً .

فهل يظهر الخطا على حسب استعمال الموقع واعني هذا الضغط عليه

واستعمالة بكثرة من قبل المستخدمين ؟

تحياتي لك

#9

بالمناسبة . اليس كثرة الاتصالات وكثرة الاغلاقات تتعب قاعدة البيانات

واعني من المفروض اني اقوم بانشاء اتصال واحد ومن ثم اقوم باستعماله في كل مرة

واعتقد ان الخطا الذي حدث هو بسبب كثرة الاتصالات التي تحدث في المشروع في وقت واحد

وعلى هذا فكثرة الاغلاقات تضر ايضا بقاعدة البيانات

فعندما انشئ اتصال في كل مرة ومن ثم اعلقة بعد هذا

فهذا يضر بقاعدة البيانات

ولكن وجدت شيفرة بسيطة تمنع من حدوث هذا الخطا او تتاكد من الاتصال

اذا كان هنالك اتصال فلا تقوم بانشاء اتصال جديد واذا لم يكن هنالك شي فسوف يقوم بانشاء اتصال

والكود التالي :

				if ( myConnection.State != ConnectionState.Open)
		{
			myConnection.Open();
		}

طبعاً لن اقوم باغلاق اي اتصال ومنها Dataset كما ذكرت

فكل ما اضع هو هذه الكود البسيط قبل حدوث اي اتصال

ويكون كود اي Method كالتالي :

	public SqlDataReader ArbitrationLogin(string username, string password)
	{
		SqlConnection myConnection = new SqlConnection(_ConnectionString);
		SqlCommand myCommand = new SqlCommand("select * from ManPower where person#='"+username +"' and password='"+password +"'", myConnection);
		myCommand.CommandType = CommandType.Text;
		try
		{
			if (myConnection.State != ConnectionState.Open)
			{
				myConnection.Open();
			}
			return myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		}
		catch (Exception)
		{
			throw;
		}
	}

فهل هذا صحيح ...؟

تحياتي لك

تم تعديل هذه المشاركة بواسطة ماكسيموس في 4 فبراير 2009 في 12:16

#10
اقتباس
بالمناسبة . اليس كثرة الاتصالات وكثرة الاغلاقات تتعب قاعدة البيانات

هذا صحيح في حالة عدم وجود pool او لهذا وجد ال pool لان الاتصال اكثر شيء مكلف

واستخدام

 if (myConnection.State != ConnectionState.Open)

لن يفيد ولن تجد اتصالا مفتوحا

#11
TareqVB كتب:
لن يفيد ولن تجد اتصالا مفتوحا

لقد قمت بوضع IF Statement في قياس حالة الاتصال هل هو متفوح او لا

كما ذكرت انا سابقاً ووضعتها قبل كل اتصال

وفي الحيقيقة عمل الموقع جيداً ولكن عندما تعرض لضغط اكثر ظهرت نفس الرسالة

وظهر نفس الخطأ .

ولهذا فأعتقد كما ذكرت ان pooling تفي بالغرض

ولقد بحثت ووجدت هذا الموقع : http://msdn.microsoft.com/en-us/library/sbbb7sce(VS.80).aspx

فهل تقصد بالـpool بان يكون داخل Connection String

فيكون كالتالي لكي لا يحدث الخطأ السابق :

SqlConnection mySqlConnection =	new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;" +
		"max pool size=10;min pool size=5"

تحياتي لك

تم تعديل هذه المشاركة بواسطة ماكسيموس في 4 فبراير 2009 في 16:16

#12
private string _ConnectionString =  ConfigurationManager.ConnectionStrings["kacstConnectionString"].ConnectionString + "max pool size=10;min pool size=5";

هنا ما السبب في ان يعطي خطأ اخر

يخبرني انه لم يتعرف على اسم المستخدم لقاعدة البيانات

والخطأ كالتالي :

Login failed for user thamer. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'smgarni'.

Source Error: 


Line 672:		catch (Exception)
Line 673:		{
Line 674:			throw;
Line 675:		}
Line 676:


Source File: c:\Inetpub\wwwroot\App_Code\DataProvider.cs	Line: 674 

Stack Trace: 


[SqlException (0x80131904): Login failed for user 'smgarni'.]
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +435
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.SqlClient.SqlConnection.Open() +111
   DataProvider.AdminLogin(String name, String pass) in c:\Inetpub\wwwroot\App_Code\DataProvider.cs:674
   LoginAdmin.Button1_Click1(Object sender, EventArgs e) in c:\Inetpub\wwwroot\LoginAdmin.aspx.cs:29
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBa
ckEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

تم تعديل هذه المشاركة بواسطة ماكسيموس في 7 فبراير 2009 في 09:21

#13

للرفع مرة أخرى

مواضيع مشابهة