Name
SqlConnection
Synopsis
This class represents a connection to a SQL Server database, which
can be opened (to execute a SQL command) or closed. For information
about the basic SqlConnection
methods and
properties, refer to the reference for the
System.Data.IDbConnection
interface, which
SqlCommand
implements. If an error is generated by
SQL Server when performing a operation over a connection, a
SqlException
is thrown.
In addition, the SqlConnection
provides some
additional provider-specific read-only properties, such as
ServerVersion
(a string with the SQL Server
version in the format xx.xx.xxxx), PacketSize
(the
size in bytes of the network packets used to communicate with SQL
Server), and WorkstationId
(a name identifying the
client, which defaults to the computer network name). The
PacketSize
property can be configured using the
Packet Size
connection string setting. You can use
a value from 512 to 32767 (the default is 8192). If your application
sends or receives large amounts of text or binary data, a larger
packet size may improve efficiency by requiring less network
activity. If applications send and receive small amounts of
information, a smaller packet size (such as 512 bytes) is more
efficient. The WorkstationId
property can also be
set through the connection string as the Workstation ID
setting.
The SQL Server provider implements connection pooling automatically, allowing connections to be reused on the same computer, provided clients use an identical connection string. ...
Get ADO.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.