Opening SqlConnection Objects
When you create an instance of a SqlConnection, it’s initialized in a "closed" state. In other words, despite its name, it’s not actually connected to your data store. If you tried to execute a query on a SqlConnection without first opening the connection, you would receive an InvalidOperationException saying that the method you called "requires an open and available Connection. The connection’s current state is closed."
To connect to your data store, supply a valid connection string, either through the constructor or by setting the object’s ConnectionString property, and then call the object’s Open method.
Calling the Open method on a SqlConnection object that’s already open will cause an InvalidOperationException ...
Get Programming Microsoft® ADO.NET 2.0 Core Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.