Jeremy Conrad

Jeremy Conrad

  • NA
  • 2
  • 6.5k

C# Multiple Queries with Microsoft SQL Server

Sep 11 2014 7:55 PM
I am writing an application in C# that connects to a database.  I am using the SqlDataReader to get the results of my SQL commands.  The problem is only one SqlData reader is allowed.  I am using Microsoft SQL Server, which is what my web hosting provider uses.

I have tried MultipleActiveResultSets=true in the connection string with no luck.

Here is my code:


 SqlConnection conn2 = new SqlConnection("Data Source=*********;Integrated Security=False;User ID=roadman1977;password=*******");
           conn2.Open();

           SqlCommand com2 = new SqlCommand("SELECT COUNT (*) FROM SiteUser WHERE Username = @Username", conn2);
           com2.Parameters.AddWithValue("@Username", txtUsername.Text);

           SqlDataReader Read = com2.ExecuteReader();

           SqlCommand com3 = new SqlCommand("SELECT COUNT (*) FROM SiteUser WHERE License = @License", conn2);
           com3.Parameters.AddWithValue("@Username", txtLicense.Text);

           SqlDataReader Read3 = com3.ExecuteReader();



Answers (1)