It sounds like you are creating a Windows Forms app so the answer is that you open the connection as late as possible and close it as early as possible. It's important to realise that ADO.NET uses connection pooling so there are two levels of connection. The DbConnection object that you create is a fairly lightweight object. The actual database connection exists at a lower level. If you open a DbConnection and then close it, then open another DbConnection with the same connection string soon after, the same low-level database connection will be used both times. ADO.NET creates one database connection per pool, where a pool is created for each unique connection string. When you open your first DbConnection, a database connection is opened and that database connection persists after you close your DbConnection. If you go for some time without opening another DbConnection then ADO.NET will close the underlying connection, otherwise it will get used repeatedly.

So, to answer your question, you open the database when you need to retrieve or save data and then you close it immediately afterwards. If you want to execute multiple queries in succession then you would open a connection before the first and close it after the last. You also don't have to use the same DbConnection object each time. Feel free to create and destroy DbConnection objects where they are used.