ANAT2403
asked on
Query too big
In ASP.NET 2.0 & SQL Server 2000
I have a page with a gridview and some textboxes.
I make a query that returns 8000 records.
I get a System.InvalidOperationExc eption because the query is to big. If I ask for the TOP 3500 It will be ok.
Is there something to do to the SqlDataAdapter to get more records?
Here is the kod:
private bool Get_Cands()
{ bool result = false;
try
{ SqlConnection conn = new SqlConnection(Configuratio nManager.C onnectionS trings["II B_DataConn ectionStri ng"].Conne ctionStrin g);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT Candidate.Candidate_id, Candidate.SurName FROM Candidate";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
conn.Open();
da.Fill(ds);
conn.Close();
GRVCandSearch.DataSource = ds;
GRVCandSearch.DataBind();
result = true;
}
catch (System.InvalidOperationEx ception ex)
{
PublicFunctions.Show_Messa ge("query_ big", Page);
}
catch (Exception ex)
{
PublicFunctions.Show_Messa ge("sys_er ror", Page, ex.Message);
}
return result;
}
}
I have a page with a gridview and some textboxes.
I make a query that returns 8000 records.
I get a System.InvalidOperationExc
Is there something to do to the SqlDataAdapter to get more records?
Here is the kod:
private bool Get_Cands()
{ bool result = false;
try
{ SqlConnection conn = new SqlConnection(Configuratio
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT Candidate.Candidate_id, Candidate.SurName FROM Candidate";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
conn.Open();
da.Fill(ds);
conn.Close();
GRVCandSearch.DataSource = ds;
GRVCandSearch.DataBind();
result = true;
}
catch (System.InvalidOperationEx
{
PublicFunctions.Show_Messa
}
catch (Exception ex)
{
PublicFunctions.Show_Messa
}
return result;
}
}
ASKER
Hi W,
The statement execute fine from a query tool in the sqlserver.
If I run a query in the visual studio 2005 in the server explorer it brings me the first 5717 records
and the I have to push the arrow to get more records. I would like to know if
there is any place that the number of records to select is limited?
If you say that a regular query should bring more records how do you do that?
The complete error:
ex.GetBaseException() {System.InvalidOperationEx ception: Internal connection fatal error.
at System.Data.SqlClient.TdsP arser.Run( RunBehavio r runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlD ataReader. CloseInter nal(Boolea n closeReader)
at System.Data.SqlClient.SqlD ataReader. Close()
at System.Data.Common.DbDataR eader.Disp ose(Boolea n disposing)
at System.Data.Common.DbDataR eader.Disp ose()
at System.Data.Common.DbDataA dapter.Fil lInternal( DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet)
at CandSearch.Get_Cands(Strin g SearchStr) in c:\Documents and Settings\Anat.BUSINESS-SOL UTI.000\My Documents\Visual Studio 2005\WebSites\IIBsite\Cand Search.asp x.cs:line 154} System.Exception {System.InvalidOperationEx ception}
Thanks
Anat
The statement execute fine from a query tool in the sqlserver.
If I run a query in the visual studio 2005 in the server explorer it brings me the first 5717 records
and the I have to push the arrow to get more records. I would like to know if
there is any place that the number of records to select is limited?
If you say that a regular query should bring more records how do you do that?
The complete error:
ex.GetBaseException() {System.InvalidOperationEx
at System.Data.SqlClient.TdsP
at System.Data.SqlClient.SqlD
at System.Data.SqlClient.SqlD
at System.Data.Common.DbDataR
at System.Data.Common.DbDataR
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at CandSearch.Get_Cands(Strin
Thanks
Anat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
First of all I would highly suggest not retriving 3000 rows and displaying them on a web page - it will be quite slow... Having said that look at paging, might come in usefull to you:
http://www.vbdotnetheaven.com/Code/Sept2003/2173.asp
From my personal experience with ADO.NET I can say I hav not yet reached a querry that retyurns too many records... I have made a data editor tool that returns 20000 + records in more than 200 columns from SQL Server and I had no problem. if you don't believe me check this thread out, clearly somone is returning more than 8000 records:
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/41813dff31ff8abd/a2be4f4225a8d7d9?lnk=st&q=SQLDataAdapter+too+many+records&rnum=5&hl=en#a2be4f4225a8d7d9
Anyways, I'm pretty sure it is a different problem. Can you debug and post the entire exception?
Also, keep incrementing the TOP statement and see on which records the error occurs, check if maybe there is something wrong in the DB?
Does the statement execute ok from a query tool?
Regards,
W