Saturday, March 31, 2012

web config problem

hi,

i have a project that i have been working on for a while, all seemed fine and worked ok, up until just now...!!

when i try to view my default.aspx page i get an error saying "Object reference not set to an instance of an object." this always worked fine, and i havent changed anything!

and it points to my connection string in my vb code..."Line 27: MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("myconnectionstring1").ConnectionString"

i have checked my web config file and the connectionstring is there. It seems as though the page isnt looking at the web config page.

Any ideas?

1. In the Web.Config check thatmyconnectionstring1is in connection String section. Note : this is case sensitive.

2.check that your page refer to same web.config virtual directory. If virtual directory is Different , then though same Parent directory .. that will give problem/


Hi there,

if you have a web application you should use WebConfigurationManager instead ConfigurationManager class. The first one is used for Web applications and the other one is for client applications.

I hope it helps.

Regards,

Fernando.


Check your MyConnection is still null in the default.aspx code-behind file.


ok i have checked all that, still getting error... here is my web config code...

12<configuration>3 <configSections>4 <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">5 <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">6 <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>7 <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">8 <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />9 <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />10 <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />11 </sectionGroup>12 </sectionGroup>13 </sectionGroup>14 </configSections>1516 <connectionStrings>17 <add name="pixiesConnectionString2" connectionString="Driver={MySQL ODBC 3.51 Driver};server=;database=;uid=;password=;option=3" providerName="System.Data.Odbc"/>18 </connectionStrings>1920 <system.web>2122 <customErrors mode="Off"/>232425 <pages>26 <controls>27 <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>28 </controls>29 </pages>30<!--31 Set compilation debug="true" to insert debugging32 symbols into the compiled page. Because this33 affects performance, set this value to true only34 during development.35 -->36 <compilation debug="false">37 <assemblies>38 <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>39 </assemblies>40 </compilation>4142 <httpHandlers>43 <remove verb="*" path="*.asmx"/>44 <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>45 <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>46 <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>47 </httpHandlers>4849 <httpModules>50 <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>51 </httpModules>525354 </system.web>5556 <system.web.extensions>57 <scripting>58 <webServices>59<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->60 <!--61 <jsonSerialization maxJsonLength="500">62 <converters>63 <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>64 </converters>65 </jsonSerialization>66 -->67 <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->68 <!--69 <authenticationService enabled="true" requireSSL = "true|false"/>70 -->7172 <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved73 and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and74 writeAccessProperties attributes. -->75 <!--76 <profileService enabled="true"77 readAccessProperties="propertyname1,propertyname2"78 writeAccessProperties="propertyname1,propertyname2" />79 -->80 </webServices>81<!--82 <scriptResourceHandler enableCompression="true" enableCaching="true" />83 -->84 </scripting>85 </system.web.extensions>8687 <system.webServer>88 <validation validateIntegratedModeConfiguration="false"/>89 <modules>90 <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>91 </modules>92 <handlers>93 <remove name="WebServiceHandlerFactory-Integrated" />94 <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"95 type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>96 <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"97 type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>98 <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />99 </handlers>100 </system.webServer>101</configuration>

also what i have noticed (which makes me think that its not reading web config correctly is that i changed the <customerrors mode> and it made no change


mike7510uk:

16 <connectionStrings>17 <add name="pixiesConnectionString2" connectionString="Driver={MySQL ODBC 3.51 Driver};server=;database=;uid=;password=;option=3" providerName="System.Data.Odbc"/>18 </connectionStrings>

So you should check pixiesConnectionString2value.

Means

MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("pixiesConnectionString2").ConnectionString


somnathmali:

mike7510uk:

16<connectionStrings>17<add name="pixiesConnectionString2" connectionString="Driver={MySQL ODBC 3.51 Driver};server=;database=;uid=;password=;option=3" providerName="System.Data.Odbc"/>18</connectionStrings>

So you should check pixiesConnectionString2value.

Means

MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("pixiesConnectionString2").ConnectionString

yes i have checked that and it is fine!

just tried changing the custom error bit again and it still makes no difference, its as if the web config isnt being read at all


ahhh all sorted now, it turns out it was a setting in IIS

thanks for help guys

0 comments:

Post a Comment