MSSQL 데이터베이스에서 정보를 가져 오는 도구를 개발 중입니다. 액세스 용 사용자 데이터베이스는 입니다. 정적을 사용하는 방법을 알고 있지만이 경우에는 확실하지 않습니다.C# 데이터베이스가 정적인지 여부
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())
{
}
}
}
}
}
}
}
내가 서버에서 데이터를 얻으려면 선택 쿼리가 있습니다
는 나는 자신의 데이터베이스 클래스가 있습니다. 자신의 스레드는 예를 들어 매시간마다 결과를 표시하는 등 일부 데이터베이스 메소드를 호출합니다. createCommand 메서드 만 정적 또는 정적이 아닌 정적 클래스 및 정적 메서드를 사용해야합니까?종류가
당신은 단위 프로젝트를 테스트합니까? 그렇다면 정적 방법을 사용하지 마십시오. 그들은 시험하기가 어렵습니다. –
이 방법을 사용하면 모든 SQL 문을 열고 실행하고 닫을 수 있습니다. 이는 매우 경제적입니다. 특히 1 시간 작업이 시작될 때마다 10 개의 쿼리를 실행하는 경우가 있습니다. – Belogix
교육용입니까? 그렇지 않다면 많은 기존 ORM 중 하나를 사용하는 것이 좋습니다. [Entity Framework] (http://msdn.microsoft.com/nl-be/data/ef.aspx), [NHibernate] (http : // nhforge. org /), [Dapper] (https://github.com/StackExchange/dapper-dot-net), ... – Stijn