VB.NET ASP.NET ConfigurationManager ConnectionString Source Code Example
I had stumbled across Lynda.com many times before, but never stopped to try it out. I recently took the plunge and started using Lynda.com to help me improve my javascript skills (See Javascript Essential Training 2007 by Dori Smith). It has revolutionized my understanding of the language! I love the fact that the exercise files allow you to follow along in real time with what the instructor is saying. Learning by doing is an extremely powerful technique. I have to give the site an A+ for both quality and content.
I am planning on using Lynda Videos to help me improve in:
- HTML
- CSS
- Classic ASP
- .NET (included in ASP section)
- AJAX
- Silverlight (in Microsoft Section)
- SharePoint (in Microsoft Section)
- Web Design
- Blogging
- SEO
- and much more

Looking for premium .NET Training Videos? The best premium .NET Videos that I have found are at Learn Visual Studio. Those videos are only about 50 cents per hour, as compared to $25 per hour that other sites charge!
LearnVisualStudio is currently having a 25% off sale ($50 savings) and giving away a free membership to TrainingSpot ($60 value) when LVS Lifetime Membership is purchased.


Limited Time Offer: Free Lifetime Membership to Progress Monitor ($24.95 value) when you purchase any membership at Learn Visual Studio, Lynda Videos or any hosting account at DiscountASP - just forward order confirmation to harvey007@sbcglobal.net
VB.NET ASP.NET ConfigurationManager ConnectionString Source Code Example
Purpose: – Illustrates using Configuration Manager to retrieve connection string from web.config file for VB.NET ASP.NET. The configuration manager can be used to do many things with regard to configuration, but this example just illustrates retrieving the connection string. Here are other methods that are available in the Configuration Manager class:
- GetSection
- GetWebAppSection
- RefreshSection
- OpenMachineConfiguration
- OpenMappedMachineConfiguration
- OpenExeConfiguration
- OpenMappedExeConfiguration
- OpenWebConfiguration
- OpenMappedWebConfiguration
Prerequistes:
- Install Visual Web Developer 2008
- Install SQL Server Express
- Download Northwind Database
- Attach Northwind Database to Databases in Sql Express
Notes:
- You can build your own library of syntax examples by using same web site over and over and just add new web forms to it.
Instructions:
- Use Visual Web Developer 2008
- Create new web site;
- Click File/New Web Site
- Select ASP.NET Website Template
- Select Visual Basic for Language
- name of Web Site could be VBNET_ASPNET_Syntax.
- Add New folder named "Configuration"
- Right-click project name in solution explorer;
- add new folder;
- name of folder could be: Configuration
- Add Web Form Named ConfigurationMgrConnectionString to Configuration folder
- Right-click Configuration folder;
- add new item;
- Select Web Form
- Check place code behind in separate file
- Web Form name could be ConfigurationMgrConnectionString
- Click on copy code in code below to copy code into web form
ConfigurationMgrConnectionString.aspx
- Click on copy code in second set of code below to copy code into code-
behind ConfigurationMgrConnectionString.aspx.vb
- Right-click on ConfigurationMgrConnectionString.aspx in solution explorer and select view in browser
Step 1: Click on Copy Code to Cut-n-paste code into ConfigurationMgrConnectionString.aspx
| XML | | copy code | | ? |
| 01 | |
| 02 | |
| 03 | <%@ Page Language="VB" AutoEventWireup="false" CodeFile="ConfigurationMgrConnectionString.aspx.vb" Inherits="Configuration_ConfigurationMgrConnectionString" %> |
| 04 | |
| 05 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 06 | |
| 07 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 08 | <head runat="server"> |
| 09 | <title></title> |
| 10 | </head> |
| 11 | <body> |
| 12 | <form id="form1" runat="server"> |
| 13 | <div> |
| 14 | <asp:GridView ID="GridView1" runat="server"> |
| 15 | </asp:GridView> |
| 16 | </div> |
| 17 | </form> |
| 18 | </body> |
| 19 | </html> |
| 20 | |
| 21 | |
| 22 |
Step 2: Click on Copy Code to Cut-n-paste code into ConfigurationMgrConnectionString.aspx.vb
| Visual Basic | | copy code | | ? |
| 01 | |
| 02 | Imports System |
| 03 | Imports System.Data |
| 04 | Imports System.Data.SqlClient |
| 05 | Partial Class Configuration_ConfigurationMgrConnectionString |
| 06 | Inherits System.Web.UI.Page |
| 07 | |
| 08 | Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| 09 | Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("Northwind_ConnectionString").ConnectionString) |
| 10 | |
| 11 | ' Create the command object |
| 12 | Dim str As String = "SELECT EmployeeID, FirstName, LastName FROM Employees" |
| 13 | Dim cmd As New SqlCommand(str, con) |
| 14 | |
| 15 | |
| 16 | Dim da As New SqlDataAdapter(cmd) |
| 17 | |
| 18 | Dim ds As New DataSet() |
| 19 | |
| 20 | da.Fill(ds, "Employees") |
| 21 | GridView1.DataSource = ds |
| 22 | GridView1.DataBind() |
| 23 | |
| 24 | End Sub |
| 25 | End Class |
| 26 | |
| 27 | |
| 28 | |
| 29 |
Step 3: Click on Copy Code to Cut-n-paste code into web.config right after the appSettings section
| XML | | copy code | | ? |
| 1 | |
| 2 | <connectionStrings> |
| 3 | <add name="Northwind_ConnectionString" |
| 4 | connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI" /> |
| 5 | </connectionStrings> |
| 6 |
Related posts:
- C# ASP.NET ConfigurationManager ConnectionString Source Code Example C# ASP.NET ConfigurationManager ConnectionString Source Code Example...
- VB.NET ASP.NET Sql Command Delete Statement Source Code Example VB.NET ASP.NET Sql Command Delete Statement Source Code Example...
- VB.NET ASP.NET Sql Command Insert Statement Source Code Example VB.NET ASP.NET Sql Command Insert Statement Source Code Example...
- VB.NET ASP.NET Sql Command Update Statement Source Code Example VB.NET ASP.NET Sql Command Update Statement Source Code Example...
- VB.NET ASP.NET Sql Command Select Statement Source Code Example VB.NET ASP.NET Sql Command Select Statement Source Code Example that...
Related posts brought to you by Yet Another Related Posts Plugin.
