Note that there are some explanatory texts on larger screens.

plurals
  1. POSqlDataReader.HasRows returns false since SQL 2008 upgrade
    primarykey
    data
    text
    <p>I've got an ASP.NET 2.0 website that connects to a SQL database. I've upgraded the SQL server from 2000 to 2008 and since then, one page refuses to work. </p> <p>I've worked out the problem is that the call to SqlDataReader.HasRows is returning false even though the dataset is not empty and removing the check allows the loop through reader.Read() to access the expected data. </p> <pre><code> _connectionString = WebConfigurationManager.ConnectionStrings["SQLServer"].ConnectionString; SqlConnection connection = new SqlConnection(_connectionString); SqlCommand command = new SqlCommand(searchtype, connection); SqlParameter _parSeachTerm = new SqlParameter("@searchterm", SqlDbType.VarChar, 255); _parSeachTerm.Value = searchterm; command.Parameters.Add(_parSeachTerm); command.CommandType = CommandType.StoredProcedure; try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) //this always returns false!? { while (reader.Read()) {... </code></pre> <p>Does anybody have any idea what's going on? There are similar code blocks on other pages where HasRows returns the correct value.</p> <p>EDIT- Just to clarify, the stored procedure DOES return results which I have confirmed because the loop runs through fine if I remove the HasRows check. Changing just the name of the SQL server in the connection string to an identical database running on SQL 2000 makes the problem go away. I've checked that NOCOUNT is off, so what else could make HasRows return false when that's not the case??</p> <p>EDIT2- Here's the SP</p> <pre><code>CREATE PROCEDURE StaffEnquirySurnameSearch @searchterm varchar(255) AS SELECT AD.Name, AD.Company, AD.telephoneNumber, AD.manager, CVS.Position, CVS.CompanyArea, CVS.Location, CVS.Title, AD.guid AS guid, AD.firstname, AD.surname FROM ADCVS AD LEFT OUTER JOIN CVS ON AD.Guid=CVS.Guid WHERE AD.SurName LIKE @searchterm ORDER BY AD.Surname, AD.Firstname GO </code></pre> <p>Many thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload