Where to Put the Connection String

In the Address Book example, you are putting the connection string in the web.config file.The web.config file has a root node named <configuration>. Under this node is the <system.web> node and you will add another node at this level called <AppSettings>.You then add a new key using the <add> tag.This new item is a key/value pair that you refer to when you need a connection string.

The web.config is an XML document that belongs in the root of your Web application. Figure 7.4 is the abbreviated text from the web.config in the sample Address Book which is included on the CD that accompanies this book. Notice the relationship of the system.web node and the AppSettings node; they are at the same child level in the document.

0 0

Post a comment