Chapter 37. Connection Strings


  • Creating connection strings for use in your application

  • Working with the Visual Studio 2010 Connection dialogs to specify how to connect to a data source

  • Accessing connection strings from within code

A large proportion of applications need to persist data, and the obvious candidate for enterprise software is a relational database. The .NET Framework provides support for working with SQL Server, SQL Server Compact Edition, Oracle, ODBC, and OLE DB databases. Many other databases are also supported through third-party providers. To connect to any of these databases, you need to specify a connection string that determines the location, the database, authentication information, and other connection parameters. This chapter explains how to create and store connection strings. In addition, you learn about encrypting and working with connection strings in code.


Connection strings are similar to XML in that, although they can be read, it is neither an enjoyable experience nor recommended to work with them directly. Because connection strings are strings, it is easy to introduce errors, misspell words, or even omit a parameter. Unlike XML, which can easily be validated against a schema, connection strings are harder to validate. The connection string wizard built into Visual Studio 2010 enables you to specify database connections without having to manually edit the connection string itself.

You can invoke the connection ...

Get Professional Visual Studio® 2010 now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.