?
Solved

ASP.NET: web.config appSettings

Posted on 2002-04-17
6
Medium Priority
?
589 Views
Last Modified: 2012-06-21
People;

I have just started a new asp.net-project in order to learn this properly, and within my project I have created a web.config-file like this:

------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
      <add key="Database" value="server=localhost;uid=sa;password=;database=mydb" />
  </appSettings>
   
  <system.web>
    <authorization>
        <allow users="*" />
    </authorization>
  </system.web>
</configuration>
------------------------------------------------------

and when I try to access this connectionstring from one of my codebehind-pages like this:
Dim Database As String = ConfigurationSettings.AppSettings("Database")
I get the following error:
BC30451: Name 'ConfigurationSettings' is not declared

Any ideas anyone??

HenningF
0
Comment
Question by:HenningF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 400 total points
ID: 6947828
Have you included System.Configuration namespace at the top of your page or the code behind file where you are tryint to access the configuration value?
0
 
LVL 1

Author Comment

by:HenningF
ID: 6947854
Nope, and when I did it worked!! Thanx... points awarded offcourse...

...but since you got off so easily maybe you can try to help me how to Dim my datagrid aswell?

-----------------------------------------------------------
Imports System
Imports System.Configuration
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient


Public Class _default
  Inherits System.Web.UI.Page
 
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
   
    Dim Klager As DataGrid    '???
    Dim Database As String = ConfigurationSettings.AppSettings("Database")
    Dim Conn As New SqlConnection(Database)
    Dim Cmd As SqlCommand
    Dim SQL As String =  "SELECT * FROM table"
   
    Conn.Open()
    Cmd = New SqlCommand(SQL, Conn)
    Klager.DataSource = Cmd.ExecuteReader()
    Klager.DataBind()
   
  End Sub
End Class
-----------------------------------------------------------

Errormessage -> BC30451: Name 'Klager' is not declared

HenningF
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 6947874
I am not a VB programmer. But I will give it a try.

Have you added a DAtaGrid web control on the page and its ID is set to Klager?

Can you show me the code from your aspx page that is including DataGrid control?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:HenningF
ID: 6947916
sure thing ->

-------------------------------------------------
<%@ Page Inherits="_default" SRC="code_default.vb" %>

<HTML>
<HEAD>
<TITLE><%=ConfigurationSettings.AppSettings("Page_title")%></TITLE>
</HEAD>

<BODY>

<FORM ID="Form1" RUNAT="server">

<ASP:DATAGRID ID="Klager" RUNAT="server"/>

</FORM>

</BODY>
</HTML>

-------------------------------------------------
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 6948173
Try moving the following line of code out of Page_Load method

Dim Klager As DataGrid

This will give your grid control variable class scope. Currently it has method scope.

Naveen
0
 
LVL 1

Author Comment

by:HenningF
ID: 6949813
I have tried to remove this line of code but I still got the same error-message; BC30451: Name 'Klager' is not declared.

What I find strange is that when i move the sub page_load into my default.aspx-file it all works fine! I did absolutely nothing to my script except moving it from the code-behind and everything just worked perfect...

I understand that I hav alot to learn

HenningF
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question