I am developing a tool which gets some information from a MSSQL database. There is an own database user for the access. I know how static works an when I should use them but in this case I am not sure.
I have an own Database class:
class Database
{
private const String connString = "the connection string";
private const String query1 = "";
public Database()
{
// some initialization
}
// some different methods which calls CreateCommand and a queryString and
// returns the result
private static void CreateCommand(string queryString, string connectionString)
{
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
sqlConnection.Open();
using (SqlCommand command = new SqlCommand(queryString, sqlConnection))
{
using (SqlDataReader dataReader = command.ExecuteReader())
{
if (dataReader != null)
{
while (dataReader.Read())
{
}
}
}
}
}
}
}
There are just select queries where I get data from the server. A own thread will call some database methods for example every hour an displays the result. Should I use a static class and static methods for this or a normal class with only the createCommand method static or nothing static?
Kind regards