I can't get 5 line web.config to work because it has connectionStrings tag

  • Thread starter Thread starter COHENMARVIN
  • Start date Start date
C

COHENMARVIN

Here is my web.config file - it has 5 lines. It causes an error
whenever I access any asp.net file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
</connectionStrings>
</configuration>
I can get rid of the error by simply deleting the 'connectionStrings'
tags. But I want to be able to put connection strings into the
web.config file in future.
Is it possible that the xml version (in line#1) is too early for
connection Strings?
Thanks,
Marvin
 
Hi Dear COHENMARVIN,

In the web.config just add the <appSettings></appSettings> in between
<configuration> and <system.web> like the following
<configuration>
<appSettings>

<add key="ConnectionInfo"
value="server=(local);database=Northwind;Integrated Security=SSPI" />

</appSettings>
<system.web>

give a Key Name for example I have given it as "ConnectionInfo" and the
value as your database details.

Thats all in the web.config.

In you code-behind file, to retrieve the Connection Info use
ConfigurationSettings.AppSettings

for example:

string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];

using(SqlConnection connection = new SqlConnection(connectionInfo))

Try this one, It will work.

For anything and everything please reply back

bye
Venkat_KL
 
That's not a valid section name. You can stick it in appSettings if you
need a custom section. Otherwise, the app doesn't recognize the value.
 
Dear W.G. Ryan - MVP ,

That's not a valid section name.

I did not get you, what do you mean by "That's not a valid section name."

You can stick it in appSettings if you need a custom section.

That is what I Have also told - "appSettings"

Otherwise, the app doesn't recognize the value.

Thats true, That is why I have also told like

In the web.config just add the <appSettings></appSettings> in between
<configuration> and <system.web> like the following
<configuration>
<appSettings>

<appSettings> is above the <system.web> , please see carefully what i have
told

You try as I have told, then reply back to me

bye
Venkat_KL
 
:
It is only a note, why <appSettings> should be out side the <System.Web> and
with in <Configuration> is <appSettings> is a Configuration Setting and it
should be accessible even from the Windows Application (Winform Application).

The Configuration Setting which is related to WebForms comes under
<System.Web>

Thats all
bye
venkat_kl
 
I don't understand what your point is. If you use appSettings it works, if
you use ConnectionString it doesn't b/c it's not valid. Where's the point
of contention with this?
 
Hi Marvin,

<connectionStrings> is only valid in ASP.NET2.0.
You are getting the error because ASP.NET1.x do not recognize
<connectionStrings> as a valid section name unless you create own custom
handler.


An
 
Back
Top