Databases Reference
In-Depth Information
I then modify my GetConString method to use the SqlConnectionStringBuilder class to dynamically build my
connection string:
string GetConString(int connType)
{
if (connType == 1)
SqlConnectionStringBuilder connstr = new SqlConnectionStringBuilder();
connstr.DataSource = dataSource;
connstr.InitialCatalog = dbName;
connstr.Encrypt = true;
connstr.TrustServerCertificate = false;
connstr.UserID = userName;
connstr.Password = userPassword;
return connstr.ToString();
...
}
Thus, consider the following when connecting to a SQL Database instance.
SqlConnectionStringBuilder class to avoid injection attacks. This class helps protect
the user ID and password from being seen and then used in an attack.
Use the
Encrypt
parameter to True and the TrustServerCertificate to False to ensure a properly encrypted
connection to avoid any man-in-the-middle attacks.
While all SQL Database traffic is encrypted and sent over port 443, be sure to set the
Use MARS (Multiple Active Results Sets) whenever possible to reduce the number of trips to
the database.
Use connection pooling to provide improved code efficiency and application performance by
reducing the number of times a new database connection must be opened. Windows Azure
SQL Database automatically terminates connections that have been idle for 30 minutes or
longer. The best practice is to design your application such that connections are opened late
and closed early.
Lastly, let's discuss some connection constraints.
Transient Fault Handling Application Block
The Transient Fault Handling Application Block provides a set of reusable components for adding retry logic into your
applications. These components can be used with the many of the Windows Azure services such as SQL Database,
Storage, Service Bus, and Caching. These components provide the resiliency applications needed in applications by
adding robust transient fault handling logic into applications.
Transient faults are errors that occur due to some type of temporary condition such as network connectivity
issues or unreliable service. In most cases, simply waiting for a brief period of time and then retrying the operation
results in a successful operation.
This is where the Transient Fault Handling Application Block comes in. The Transient Fault Handling Application
Block (we'll call it TFHAB from here to save space. . . and typing) is part of Microsoft's Enterprise Library. It is
the result of some great collaboration between the Microsoft Patterns & Practices group and the Windows Azure
Customer Advisory team.
The TFHAB works by using detection strategies to identify all known transient error conditions, making it easy for
developers to define retry policies based on the built-in retry strategies.
 
Search WWH ::




Custom Search