ADO.NET and SQL Server Performance Tips ADO.NET provides several different methods to access SQL Server data, including OLE DB.NET, ODBC.NET, SQLXML, and the SQL Server .NET data provider. Of all of these, the SQL Server .NET data provider is the fastest, as much as 30-40% faster than the others. The SQL Server .NET provider uses TDS (Tabular Data Stream, which is the native SQL Server data format) to communicate with SQL Server. The SQL Server .NET provider can be used to connect to SQL Server 7.0 and SQL Server 2000 databases, but not SQL Server 6.5 databases. If you need to connect to a SQL Server 6.5 database, the best overall choice is the OLE DB.NET data provider. [7.0, 2000] Added 2-25-2002 ADO.NetÀº SQL Server¿¡ Á¢±ÙÇϱâ À§ÇÑ ¹æ¹ýÀ¸·Î OLE DB.NET, ODBC.NET, SQLXML, SQL Server .NET¿Í °°Àº data provider¸¦ Á¦°øÇÑ´Ù. ÀÌ Áß Server .NET data provider°¡ °¡Àå ºü¸£¸ç, ´Ù¸¥ ¹æ¹ý¿¡ ºñÇØ ¾à 30~40% ºü¸£´Ù. Server .NET data provider´Â SQL Servr¿ÍÀÇ Åë½Å¿¡ TDS(Tabular Data Stream, which is the native SQL Server data format)¸¦ »ç¿ëÇÑ´Ù. SQL Server .NET provider´Â SQL Server 7.0°ú SQL Server 2000 µ¥ÀÌÅͺ£À̽º Á¢¼Ó¿¡ »ç¿ëÇÒ ¼ö ÀÖÀ¸³ª SQL Server 6.5¿¡´Â »ç¿ëÇÒ ¼ö ¾ø´Ù. ¸¸¾à SQL Server 6.5 Á¢¼ÓÀÌ ÇÊ¿äÇÏ´Ù¸é °¡Àå ÁÁÀº ¹æ¹ýÀº OLE DB.NET data provider¸¦ ÀÌ¿ëÇÏ´Â °ÍÀÌ´Ù. ***** When using ADO.NET to make connections to SQL Server, always be sure you explicitly close any Connection, Recordset, or Command objects you have opened. While letting an object go out of scope will in affect close the object, it is not the same as explicitly closing an object. By explicitly closing these objects and setting them to nothing, you do two things. First, you remove the object sooner than later, helping to free up resources. Second, you eliminate the possibility of "connection creep". Connection creep occurs when connection or resource pooling is used and when connections are not properly closed and released from the pool. This helps to defeat the purpose of pooling and reduces SQL Server's performance. [7.0, 2000] Added 2-25-2002 ***** When you specify a server in an ADO.NET connection string, use the server's IP address, not the server's DNS name. By using an IP address instead of a DNS name, name resolution does not have to occur, reducing the amount of time it takes for a connection to be made. A server's IP address can be used to specify either a default or named instance of a server running SQL Server. [ 7.0, 2000] Added 2-25-2002 ADO.NetÀÇ Connection String¿¡ ¼­¹ö¸¦ ±â¼úÇÒ ¶§, DNS À̸§À» »ç¿ëÇÏÁö ¸»°í ¼­¹öÀÇ IP address¸¦ »ç¿ëÇ϶ó. DNSÀ̸§ ´ë½Å IP address¸¦ »ç¿ëÇÏ°Ô µÇ¸é, À̸§ Ç®ÀÌ(name resolution)¸¦ ÇÊ¿ä·Î ÇÏÁö ¾Ê±â ¶§¹®¿¡, ¿¬°áÀ» ¸¸µå´Â ½Ã°£À» ÁÙÀÏ ¼ö ÀÖ´Ù. ¼­¹öÀÇ ip address¸¦ ±âº» ÀνºÅϽº ȤÀº µ¿ÀÛÁßÀÎ SQL ServerÀÇ ¸í¸íµÈ ÀνºÅϽº¸¦ ±â¼úÇÏ´Â µ¥ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ***** While SQL Server application roles are handy, they can also negatively affect your application's performance. The reason for this is that a connection to SQL Server using an application role cannot take advantage of connection pooling. In effect, connection pooling is turned off for any connections using application roles. If your application will be making many connections to SQL Server, avoid applications roles for your application's connections. [ 7.0, 2000] Added 2-25-2002 ***** To get the most out of connection pooling in ADO.NET, keep the following in mind when developing your applications: Be sure than your connections use the same connection string each time. Connection pooling only works if the connection string is the same. If the connection string is different, then a new connection will be opened. Only open a connection when you need it, not before. Close your connection as soon as you are done using it. Don't leave a connection open if it is not being used. Be sure to drop any temporary objects before closing a connection. Be sure to close any user-defined transactions before closing a connection. Don't use application roles if you want to take advantage of connection pooling. [ 7.0, 2000] Added 2-25-2002 ***** Disconnected recordsets in ADO.NET outperform disconnected recordsets in traditional ADO. ADO.NET is faster than ADO for disconnected recordsets because under ADO, COM marshalling between tiers requires that values in a recordset be converted to values recognized by COM. Under ADO.NET, data type conversion is not required, boosting performance. [ 7.0, 2000] Added 2-25-2002 ADO.NETÀÇ ºñ¿¬°áÇü recordsetsÀÇ ¼º´ÉÀÌ ±âÁ¸ÀÇ ADOÀÇ ºñ¿¬°áÇü recordsetº¸´Ù ¼º´ÉÀÌ ¶Ù¾î³ª´Ù. ADO.NETÀÇ ºñ¿¬°áÇü recordsetÀÌ ADOÀÇ ºñ¿¬°áÇü recordsetº¸´Ù ºü¸£´Ù. ÀÌÀ¯´Â ADO ÇÏÀ§ °èÃþ¿¡¼­ recordsetÀÌ COMÀÌ ÀνÄÇÒ ¼ö ÀÖ´Â °ªÀ¸·Î º¯È¯µÇ´Â tier °£ÀÇ COM ¸¶¼£¸µ(marshalling) ¶§¹®ÀÌ´Ù. ADO.NET ÇÏÀ§ °èÃþ¿¡¼­´Â µ¥ÀÌÅÍ Å¸ÀÔ º¯È¯ÀÌ ÇÊ¿ä ¾ø±â ¶§¹®¿¡ º¸´Ù ÁÁÀº ¼º´ÉÀ» ¹ßÈÖÇÑ´Ù. ***** When possible, use the ExecuteNonQuery method with SQLCommand objects, as this is the most efficient way to execute queries from ADO.NET. Use output parameters with SQLCommand objects if you need to retrieve just a few values, or a single data row, instead of using more expensive techniques, such as a SQLDataAdapter, a SQLDataReader, or a strongly typed DataSet. [2000] Added 3-27-2002 Read an article about ADO.NET. °¡±ÞÀû ExecuteNonQuery ¸Þ¼Òµå¿Í SQLCommand °´Ã¼¸¦ »ç¿ëÇ϶ó. ÀÌ°ÍÀÌ ADO.Net¿¡¼­ Äõ¸®¸¦ ½ÇÇàÇÏ´Â °¡Àå È¿°úÀûÀÎ ¹æ¹ýÀÌ´Ù. ¸î°³ÀÇ °ªÀ» ¾ò¾î¿À°Å³ª ÇϳªÀÇ data row¸¦ ¾ò¾î¿Í¾ß ÇÒ °æ¿ì¿¡´Â SQLDataAdapter, SQLDataReader ȤÀº DataSet°ú °°Àº ºñ¿ëÀÌ Å« ¹æ¹ý ´ë½Å SQLCommand °´Ã¼¿Í output parameters¸¦ »ç¿ëÇ϶ó.