Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (20.24 KB, 2 trang )
Understanding the SqlConnection Class
You use an object of the SqlConnection class to connect to a SQL Server database, and
this object handles the communication between the database and your C# program.
Note Although the SqlConnection class is specific to SQL Server, many of the properties,
methods, and events in this class are the same as those for the OleDbConnection
and OdbcConnection classes. If a property or method is specific to SqlConnection,
it says so in the Description column of the tables shown in this section. You can
look up the exact properties, methods, and events for a specific class using the .NET
online reference. You saw how to do that in Chapter 1
, "Introduction to Database
Programming with ADO.NET."
Table 7.1
shows some of the SqlConnection properties.
Table 7.1: SqlConnection PROPERTIES
PROPERTY TYPE DESCRIPTION
ConnectionString string Gets or sets the string used to open a database.
ConnectionTimeout int Gets the number of seconds to wait while trying to
establish a connection to a database. The default is
15 seconds.
Database string Gets the name of the current database (or the
database to be used once the connection to the
database is made).
DataSource string Gets the name of the database server.
PacketSize int Gets the size (in bytes) of network packets used to
communicate with SQL Server. This property
applies only to the SqlConnection class. The
default is 8,192 bytes.
ServerVersion string Gets a string containing the version of SQL Server.
State ConnectionState Gets the current state of the connection: Broken,