Solved

ASP.NET: web.config appSettings

Posted on 2002-04-17
6
586 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 100 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
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!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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