The Perfect Method To Access SQL Server Data
As I continue to program and experiment with C#/.Net technologies I develop new “favorite” ways of doing things. This is my current iteration of the perfect call to SQL Server. I use this style of method in middle layer classes that are called from ASP.NET pages and need access to SQL Server. This style of method is built on many things, including a good understand of how SQL server works, real life performance and scalability testing, and the new fondness for yield return. public IEnumerable<Member> Members() { using (SqlConnection sqlConnection = new SqlConnection( ConfigurationManager.ConnectionStrings[ "connectionstring" ].ConnectionString)) { sqlConnection.Open(); StringBuilder sql = new StringBuilder(); sql.Append( "SELECT memberId\r\n" ); sql.Append( "FROM tbMembers\r\n" ); sql.Append( "WHERE deleted = 0 AND companyId = @CompanyId\r\n" ); ...