Solved

ASP.NET: web.config appSettings

Posted on 2002-04-17
6
583 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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/…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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