It's not a problem. Creating a database class has a small overhead.
However, actually creating a database connection has a lot of overhead, which is why Windows does a connection pool. In short, the first time a process creates a connection to a database, it scans the connection pool for an existing connection with exactly the same connection string. If he does not find it, he creates a new one (expensive operation). When a process closes it and allows it to go out of scope, it does not actually close the connection to the database, it places it in the Connection Pool. Remains until the same process creates another connection with the same connection string. Then it gives you an existing one from the connection pool.
You can disable the connection pool (using the settings in the connection string), but this is usually a very bad idea.
source share