Der appSettings-node muss VOR den system.web node:
<appSettings>
<add key="myConn"
value="server=aeraserver;uid=sa;pwd=top.secret;database=Northwind" />
</appSettings>
<system.web>
...
Kai
-----Original Message-----
From: Frank Tichy [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 18, 2002 10:49 AM
To: aspDEdotnet
Subject: [aspdedotnet] Problem: Verwaltung von DSNs in der Web.config
Hai zusammen,
ich empfand die in dem Artikel Web.Config 101
(http://www.aspheute.com/artikel/20010802.htm) beschriebene Methode zur
zentralen "Verwaltung" eines oder meherer DSNs als aeusserst praktisch. Bei
mir funktioniert das allerdings nicht so wie in dem Artikel beschrieben.
Wenn ich beispielsweise die Web.config um den Eintrag
"<system.web>
...
<appSettings>
<add key="myConn"
value="server=aeraserver;uid=sa;pwd=top.secret;database=Northwind" />
</appSettings>
...
<system.web>"
erweitere bringt mir das Framework nach dem Kompilieren meines Projekts
folgenden Fehler:
"Configuration Error
Description: An error occurred during the processing of a configuration file
required to service this request. Please review the specific error details
below and modify your configuration file appropriately.
Parser Error Message: Unrecognized configuration section 'appSettings'
Source Error:
Line 10: <system.web>
Line 11:
Line 12: <appSettings>
Line 13: <add key="myConn"
value="server=myserver;uid=sa;pwd=;database=Northwind" />
Line 14: </appSettings>
Source File: c:\inetpub\wwwroot\testweb\web.config Line: 12
------------------------------------------------------------------------
--------
Version Information: Microsoft .NET Framework Version:1.0.3705.288; ASP.NET
Version:1.0.3705.288"
Nach laengerem Ueberlegen erweiterte ich die Web.config um folgenden
Eintrag:
"<configSections>
<sectionGroup name="system.web">
<section name="appSettings"
type="System.Configuration.NameValueSectionHandler,System" />
</sectionGroup>
</configSections>"
Damit laesst sich obige Fehlermeldung beseitigen. Allerdings klappt nun das
Auslesen von myConnStr nicht. Dazu verwende ich folgendes script:
"<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E )
{
String strDsn = ConfigurationSettings.AppSettings["myConn"];
SqlConnection myConnection = new SqlConnection(strDsn);
SqlCommand myCommand = new SqlCommand("SELECT ProductName FROM
Products", myConnection);
//Response.Write("myConnStr: " + strDsn + "<br>");
myConnection.Open();
SqlDataReader dr = myCommand.ExecuteReader();
while (dr.Read())
{
Response.Write(dr["ProductName"] + "<br>");
}
myConnection.Close();
}
</script>"
welches mit dieser Fehlermeldung quitiert wird:
"The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The ConnectionString
property has not been initialized.
Source Error:
Line 29: //Response.Write("myConnStr: " + strDsn + "<br>");
Line 30:
Line 31: myConnection.Open();
Line 32:
Line 33: SqlDataReader dr = myCommand.ExecuteReader();
Source File: c:\inetpub\wwwroot\testweb\test.aspx Line: 31
Stack Trace:
[InvalidOperationException: The ConnectionString property has not been
initialized.]
System.Data.SqlClient.SqlConnection.Open()
ASP.test_aspx.Page_Load(Object Src, EventArgs E) in
c:\inetpub\wwwroot\testweb\test.aspx:31
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
------------------------------------------------------------------------
--------
Version Information: Microsoft .NET Framework Version:1.0.3705.288; ASP.NET
Version:1.0.3705.288"
Wenn ich den ConnectionString herkoemmlich ueber "SqlConnection myConnection
= new SqlConnection("server=myserver;uid=sa;pwd=;database=Northwind");"
initialiesere funktioniert alles.
Fehlt mir ein Eintrag in der machine.config oder geht das Ganze nur mit
DataSets(macht ja eigentlich keinen Sinn)? Was mache ich falsch? Ach ja,
das .Net Framework ist frisch mit Service Pack 2 installiert.
Danke im vorraus
Frank
| [aspdedotnet] als [EMAIL PROTECTED] subscribed
| http://www.dotnetgerman.com/archiv/aspdedotnet/ = Listenarchiv Sie
| k�nnen sich unter folgender URL an- und abmelden:
| http://www.dotnetgerman.com/listen/aspDEdotnet.asp
| [aspdedotnet] als [email protected] subscribed
| http://www.dotnetgerman.com/archiv/aspdedotnet/ = Listenarchiv
| Sie k�nnen sich unter folgender URL an- und abmelden:
| http://www.dotnetgerman.com/listen/aspDEdotnet.asp