title: Reading and writing data into sql server simultaneously
body: <p>I have a service which continuously writes data in a separate thread into SQL database.Now from the same service if i am trying to read from the same table, since i already am writing into it,I get this exception : There is already an open DataReader associated with this Command which must be closed first.
  So can anyone help me how to do this simultaneously? </p>
  
  <p>Here s my code  for reading data:</p>
  
  <p>public Collection ReadData(string query)
          {</p>
  
  <pre><code>        {
  
              _result = new Collection&lt;string[]&gt;();
              string[] tempResult;
              SqlDataReader _readerRead;
              using (_command = new SqlCommand(query, _readConnection))
              {
                  _readerRead = _command.ExecuteReader();
                  while (_readerRead.Read())
                  {
                      tempResult = new string[4];
                      tempResult[0] = _reader[0].ToString();
                      tempResult[1] = _reader[1].ToString();
                      tempResult[2] = _reader[2].ToString();
                      tempResult[3] = _reader[3].ToString();
                      _result.Add(tempResult);
                      //Console.WriteLine("Name : {0} Type : {1} Value : {2} timestamp : {3}", _reader[0], _reader[1], _reader[2], _reader[3]);
  
                  }
                  if (_readerRead != null)
                  {
                      _readerRead.Close();
                  }
                  _readConnection.Close();
                  return _result;
  
              }
          }
      }
  </code></pre>
  
  <p>and here it is for writing to it :</p>
  
  <pre><code>public void WriteData(Collection&lt;TagInfo&gt; tagInfoList)
      {
  
          int i = 0;
          for (i = 0; i &lt; tagInfoList.Count; i++)
          {
             using( _command = new SqlCommand(insert statement here)
              {
                  _command.Parameters.AddWithValue("Name", tagInfoList[i].Name);
                  _command.Parameters.AddWithValue("Type", tagInfoList[i].TagType);
                  _command.Parameters.AddWithValue("Value", tagInfoList[i].Value);
                  _reader = _command.ExecuteReader();
                  if (_reader != null)
                  {
                      _reader.Close();
                  }
              }
          }
  
      }
  </code></pre>