none
DataReader - Cannot read rows in ASP / in ConsoleApp can RRS feed

  • Question

  • Hi

    I have attached AdventureWorksLT database using SQL Server Management Studio Express to my database engine. I had set owner to the account I'm working on. The following peace of code I use in both: Console application and asp.net application.

    using (SqlConnection conn = new SqlConnection(@"Data source=DJPITER-PC\SQLEXPRESS; 
                    Initial Catalog=AdventureWorksLT;Integrated Security=SSPI")) 
                { 
                    SqlCommand comm = new SqlCommand("SELECT ProductID FROM SalesLT.Product",conn); 
                    conn.Open(); 
     
                    SqlDataReader reader = comm.ExecuteReader(); 
     
                    while (reader.Read()) 
                    { 
                         
                    } 
     
                    reader.Close(); 
                } 

    The only real problem is that in console application's while loop iterates over the set of rows, while in asp.net (VS WebDeveloper server) reader.Read() returns false (reader.hasRows is true). I am using debugger.

    Do you have any idea what could be wrong?

    PS: The same situation is on any database created locally - not attached.

    Kind Regards
    PK
    Thursday, March 5, 2009 11:46 AM

All replies

  • Can you see any difference in traces on the SQL Server between the two applications?
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, March 20, 2009 8:25 PM
    Moderator