TOGGIT - IN SEARCH OF CERTIFICATION
 TOGGIT
     IN SEARCH OF CERTIFICATION
    
     
  
TOGGIT IN SEARCH OF CERTIFICATION

Visual Basic .Net Sample Code and Applications

MAIN
Logon to ToggIT
Join ToggIT
Home
Home
Contact Us
Career Building
Certification Maps
Partners
Technopedia
.Net Source Code
Free Networking Tools
Free IT Publications
Microsoft
2003 Certifications
270 Win XP Pro
290 2003 Server
291 2003 Network Inf
293 Plan Network inf
294 2003 Active Directory
224 Exchange 2000
DBA Certifications
228 SQL 2000
229 SQL 2000
MCSD Certifications
526 Windows Apps
305 ASP.NET
2000 Certifications
210 Professional
215 Server
216 Network inf.
217 Directory Svc.
218 Managing 2K
219 Design Dir Svc.
220 Design Security
270 Win XP Pro
221 Design Net Inf.
Cisco
CCNA
CompTia
A+ Hardware 2003!
A+ Software 2003!
Network+
Security+
New Wireless
CWNP program
Java 
Java Goodies 



MCSE Top-Rated Sites



 

Join Toggit Now!
Avoid Annoying Ads!

 Your Email:

 New Password:

See the list of .Net articles
How do I store my Connection string or other data in my Web.Config file?

In a data intensive web site, you may have to reference your connection string in many places in your code. When you publish your site the production server has a different connection string than your development server. Rather than change this string in your code, you can store your connection string, or any other configuration data in your Web.Config file. Here's how:

The Web.Config file is an editable XML based configuration file in your web application's root directory. Be careful, web.config entries are case sensitive!

To store configuration strings in the file, you need to add a section to top of the web.config:
 

<!-- Web.Config Configuration File -->
<configuration>
  <appSettings>
    <add key="ConString" value="server=local;database=MyDb" />
  </appSettings>

  <system.web>

<!-- the rest of the web.config follows...
Note: The connection string has been shortened to fit in this space.


Now that the data is stored in the web.config, you can retrieve it from anywhere in your code.

You can store any string, and give the key any name you want. You can use it to store a path name, or business info, or whatever.

In any page in your site this code would be used to retrieve the connection string:
 

Dim ConS as string
ConS = ConfigurationSettings.AppSettings("ConString")

Notice that the key name is the same as the key name that you used to store the data.

Note: It is a good idea to make a backup of your web.config file before you edit it. If there is an error in your web.config file, your application will fail to run!

 


Study and Research resources:
Microsoft Certification Info:
 
See the list of .Net articles

 

TOGGIT      IN SEARCH OF CERTIFICATION

All information on this site is copyright ToggIT.com unless otherwise specified. Material submitted or posted this site may also contain materials that are copyrights of individual contributors. It is illegal to copy, publish, reproduce, or distribute any materials from this site with the express permission of the owner of this material.

The material on this web site is not sponsored by, endorsed by or affiliated with Microsoft, Inc, CompTIA, or Cisco Systems, Inc. Microsoft, Inc.® ,Windows XP, Windows 2000, Windows 2000 Server, Windows 98, Windows NT, Visual Basic, Visual C++, Visual FoxPro, SQL server and Microsoft logos are trademarks or registered trademarks of Microsoft,  Inc. in the United States and certain other countries. A+, Server+, and Network+ are all registered trademarks of CompTIA. CCNA, CCNE, and the Cisco logo are all registered trademarks of Cisco Systems. All other trademarks are trademarks of their respective owners.