title: Why am I getting this database connectivity error in SQL Server?
body: <p>I'm a beginner in Database programming and am having trouble connecting to my database.  I use the following code for connectivity.</p>
  
  <pre><code>public class dbOpnClse
  {
      SqlConnection con = new SqlConnection();
      public SqlConnection openConnection()
      {
          con.ConnectionString ="server=SERVERNAME;database=Test;uid=###;pwd=#####";
          con.Open();
          return con;
      }
      public void closeConnection()
      {
          con.Close();
      }
  }
  </code></pre>
  
  <p>The problem is that I am getting the exception "Not allowed to change the 'ConnectionString' property. The connection's current state is open." Is there any error in this connectivity code? Please help!  I'm using C#.net 2005 and SQL Server 2000</p>