VB.NET ASP.NET ConfigurationManager ConnectionString Source Code Example

"I tried to learn .NET by taking boot camp classes that cost me $6,000. After taking the classes, I discovered tons of free (and very cheap) videos on the internet created by experts in the field. I found the videos to be much better than the classrooms. The videos were presented by Microsoft presenters that knew the material backwards and forwards, and they were much cheaper and better than the classroom teachers. I have spent the last three years organizing and hunting down the videos for my own use and decided that all could benefit by sharing what I found." - Wade Harvey

Click Here for Free 24 hour pass to lynda.com.

I AM VERY EXCITED ABOUT THIS AMAZING NEW DISCOVERY

Over 40,000 Top-Notch Video Tutorials (or 3,452 hours) on Lynda.com

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:

  1. HTML
  2. CSS
  3. Classic ASP
  4. .NET (included in ASP section)
  5. AJAX
  6. Silverlight (in Microsoft Section)
  7. SharePoint (in Microsoft Section)
  8. Web Design
  9. Blogging
  10. SEO
  11. and much more
You can learn more about Lynda.com by watching the 5-minute video at About Lynda.com. If you are only focusing on .NET, you are missing out on the "big picture" and on many of the underlying fundamentals! To be an Ideal Programmer, you need to have the largest knowledge base possible.

JavaScript tutorials



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.


DiscountASP .NET hosting JavaScript tutorials


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 to retrieve 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:

  1. Install Visual Web Developer 2008
  2. Install SQL Server Express
  3. Download Northwind Database
  4. 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:

  1. Use Visual Web Developer 2008
  2. 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.
  3. Add New folder named "Configuration"
    • Right-click project name in solution explorer;
    • add new folder;
    • name of folder could be: Configuration
  4. 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
  5. Click on copy code in code below to copy code into web form

    ConfigurationMgrConnectionString.aspx

  6. Click on copy code in second set of code below to copy code into code-

    behind ConfigurationMgrConnectionString.aspx.vb

  7. 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:

  1. C# ASP.NET ConfigurationManager ConnectionString Source Code Example C# ASP.NET ConfigurationManager ConnectionString Source Code Example...
  2. VB.NET ASP.NET Sql Command Delete Statement Source Code Example VB.NET ASP.NET Sql Command Delete Statement Source Code Example...
  3. VB.NET ASP.NET Sql Command Insert Statement Source Code Example VB.NET ASP.NET Sql Command Insert Statement Source Code Example...
  4. VB.NET ASP.NET Sql Command Update Statement Source Code Example VB.NET ASP.NET Sql Command Update Statement Source Code Example...
  5. 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.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

This blog uses the cross-linker plugin developed by Web-Developers.Net