''SqlConnection'' ''marshal by reference, disposable'

SqlConnection marshal by reference, disposable

System.Data.SqlClient (system.data.dll) sealed class

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.

public sealed class SqlConnection : System.ComponentModel.Component , System.Data.IDbConnection, ICloneable {
// Public Constructors
   public SqlConnection(  );  
   public SqlConnection( string connectionString);  
// Public Instance Properties
   public string ConnectionString{set; get; }                  // implements System.Data.IDbConnection
   public int ConnectionTimeout{get; }                         // implements System.Data.IDbConnection
   public string Database{get; }                               // implements System.Data.IDbConnection
   public string DataSource{get; } 
   public int PacketSize{get; } 
   public string ServerVersion{get; } 
   public ConnectionState State{get; }                         // implements System.Data.IDbConnection
   public string WorkstationId{get; } 
// Public Instance Methods
   public SqlTransaction BeginTransaction(  );  
   public SqlTransaction BeginTransaction(System.Data.IsolationLevel iso);
   public SqlTransaction BeginTransaction(System.Data.IsolationLevel iso, string transactionName);
   public SqlTransaction BeginTransaction(string transactionName);
   public void ChangeDatabase( string database);               // implements System.Data.IDbConnection
   public void Close(  );                                        // implements System.Data.IDbConnection
   public SqlCommand CreateCommand(  );  
   public void EnlistDistributedTransaction(System.EnterpriseServices.ITransaction transaction);
   public void Open(  );                                         // implements System.Data.IDbConnection
// Protected Instance Methods
   protected override void Dispose( bool disposing);           // overrides System.ComponentModel.Component
// Events
   public event SqlInfoMessageEventHandler InfoMessage;  
   public event StateChangeEventHandler StateChange;  


System.Object figs/U2192.gif System.MarshalByRefObject figs/U2192.gif System.ComponentModel.Component(System.ComponentModel.IComponent, System.IDisposable) figs/U2192.gif SqlConnection(System.Data.IDbConnection, System.ICloneable)

Returned By

SqlCommand.Connection , SqlTransaction.Connection

Passed To

SqlCommand.{Connection , SqlCommand( )} , SqlDataAdapter.SqlDataAdapter( )

    Part I: ADO.NET Tutorial
    Part II: ADO.NET Core Classes
    Part III: API Quick Reference
    Chapter 34. The System.Data Namespace