Databases Reference
In-Depth Information
Figure 5-14. Projects in Solution Explorer
That was quite the example, but let's discuss some best practices that pertain to the application when connecting
to Windows Azure SQL Database.
Best Practices
Let's spend a few minutes talking about some things you should consider when developing applications for the
cloud. We've spent a large portion of this chapter discussing how to connect to SQL Database, but even before
you start coding, the very first thing you should consider is your connection. First and foremost, secure your
connection string from injection attacks and man-in-the-middle attacks. The .NET Framework provides a simple
class in which to create and manage the contents of connection strings used by the SqlConnection class. This is the
SqlConnectionStringBuilder class.
The following example illustrates how to use this class. I first define four static variables to hold the username,
password, database name and server:
private static string userName = "SQLScott@ server ";
private static string userPassword = password ;
private static string dataSource = "tcp: server .database.windows.net";
private static string dbName = "AdventureWorks2012";
 
Search WWH ::




Custom Search