Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SqlConnection.PacketSize Property

Gets the size (in bytes) of network packets used to communicate with an instance of SQL Server.

Namespace: System.Data.SqlClient
Assembly: System.Data (in system.data.dll)

public int PacketSize { get; }
/** @property */
public int get_PacketSize ()

public function get PacketSize () : int

Not applicable.

Property Value

The size (in bytes) of network packets. The default value is 8192.

If an application performs bulk copy operations, or sends or receives lots of text or image data, a packet size larger than the default may improve efficiency because it causes fewer network read and write operations. If an application sends and receives small amounts of information, you can set the packet size to 512 bytes (using the Packet Size value in the ConnectionString), which is sufficient for most data transfer operations. For most applications, the default packet size is best.

PacketSize may be a value in the range of 512 and 32767 bytes. An exception is generated if the value is outside this range.

The following example creates a SqlConnection, including setting the Packet Size to 512 in the connection string. It displays the PacketSize and ServerVersion properties in the console window.

private static void OpenSqlConnection()
    string connectionString = GetConnectionString();
    using (SqlConnection connection = new SqlConnection(connectionString))
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine("PacketSize: {0}", connection.PacketSize);

static private string GetConnectionString()
    // To avoid storing the connection string in your code, 
    // you can retrieve it from a configuration file, using the 
    // System.Configuration.ConfigurationSettings.AppSettings property 
    return "Data Source=(local);Initial Catalog=AdventureWorks;"
        + "Integrated Security=SSPI;Packet Size=512";

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

© 2015 Microsoft