Solved

ASP.NET: web.config appSettings

Posted on 2002-04-17
6
579 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
  • 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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 video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now