Solved

ASP.NET: web.config appSettings

Posted on 2002-04-17
6
588 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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/…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

707 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