39.2. SQL Server Format

Probably the most familiar data provider is the SQL Server database provider, so Table 39-1 details some of the common connection properties you may need to specify to connect to your database server.

Table 39.1. Some Common Connection Properties
Connection PropertyDescription
Asynchronous ProcessingDetermines whether the connection will support asynchronous database calls. Most applications try to deliver a responsive user interface, so it is important for it not to freeze when retrieving data. In the past this could only be achieved by doing the data processing in a separate thread from the user interface. The data access methods, such as ExecuteNonQuery, now support calls using the Begin and End asynchronous pattern. For example, BeginExecuteNonQuery will return immediately so the user interface does not block while the data access is performed.
AttachDBFilenameIntroduced in SQL Server 2005, this property means you can work with databases that aren't permanently attached to a SQL Server instance. This property is a path reference to the primary database file that contains the database. Specifying AttachDBFilename effectively attaches and detaches the database when required.
Connect TimeoutDetermines the maximum length of time that the Open method will block when attempting to connect to the database. This should not be confused with the Timeout property on the SQLCommand class, which determines the timeout for a given command to execute.
Data SourceThe host name or IP address of the instance of SQL Server that the connection will be accessing. In cases where multiple instances exist on a given machine, or where SQL Server has been assigned an instance name other than the default instance, this needs to be specified as part of the Data Source field, for example, 192.168.205.223InstanceName.
Initial CatalogSpecifies the name of the database to connect to.
Integrated SecurityIf Integrated Security is used, the Windows credentials of the current user will be used to connect to the database server. To provide user ID and password, this property must be set to false. Also be aware that when working with ASP.NET using Windows authentication without impersonation, if Integrated Security is enabled, the authenticated web user's credentials will be used to access the database server.
MultipleActiveResultSetsAllows multiple result sets to be returned across a given connection. For example, a single database command mightcontain two SELECT statements. If the MultipleActiveResultSets property is enabled, the results of both SELECT statements will be returned and can be used to populate a DataSet. This property is compatible only with SQL Server 2005 and above.
PasswordUsed for the SQL Server user account used to access the database server.
User IDSpecifies the SQL Server account used to access the database server. Mixed-mode authentication for the SQL Server must be enabled, and the Integrated Security property must be set to false.

Each connection string property must be specified as it appears in the preceding table, but they can be in any order in the connection string. A semicolon is used to separate each property. An example connection string might be as follows:

Data Source=drnick;Initial Catalog=AdventureWorks;Integrated Security=True;
MultipleActiveResultSets=True

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.45.5