Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All

 

I am facing SQL Server Timeout exception.

 

try

{

 

SetStoredProcCommand(SPRetrieveIntSchedReport, DatabaseConfigKey);

 

AddInParameter("@FromDate", DbType.DateTime, schedule.FromDate);

 

AddInParameter("@ToDate", DbType.DateTime, schedule.ToDate);

 

AddInParameter("@ApplnType", DbType.String, schedule.ApplnType);

 

IDataReader dataReader = ExecuteReader();

 

while (dataReader.Read())

{ .....}

}

When the control reaches the data reader its taking much time to enter the WHILE loop, and some times its getting in and its done fine,but sme times facing this SQL SERVER TIMEOUT EXCEPTION.

 

please help.

 

Thanks in advance.

  • 2 weeks later...
Posted

Have you tried putting the results in an adapter and parsing it after the data set is closed?

 

For example:

 

protected void SQLFunction()
{
DataTable dt = new DataTable();
using (SqlConnection myConn = new SqlConnection(strConnect))
{
	string strSQL = "SELECT TOP 10000 * FROM [TableName]";
	myConn.Open();
	SqlCommand myCommand = new SqlCommand(strSQL, myConn);
	SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
	myAdapter.Fill(dt);
	myConn.Close();
}
foreach (DataRow row in dt.Rows)
{
	lblResults.Text += row[0].ToString() + "<br />";
}
}

 

With those code, I took 10,000 results and was able to display everything from the first column without a timeout.

 

Of course, you'd need to adapt this to use the Stored Procedure that you want.

 

In my database, I have 31 columns in the particular table I tried it on and this entire code executed in roughly 12 seconds.

 

I hope this helps!

 

~Derek

Check out my blog! DevPaper.NET

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...