Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all

following error occored.


Server Error in '/' Application.
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 23: 
Line 24:         //Database connection strings
Line 25:         public static readonly string ConnectionString_Synergy = ConfigurationManager.AppSettings["LocalMySqlServer"].ToString();
Line 26:         public static readonly string ConnectionString_Hospital = ConfigurationManager.AppSettings["DefaultConnectionString"].ToString();
Line 27: 


Source File: c:\inetpub\vhosts\synergyactiongroup.com\httpdocs\App_Code\CSharp\SQLHelper.cs    Line: 25



below is web.config code


XML
<?xml version="1.0" encoding="UTF-8"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
  <configSections>
    <!--<section name="urlrewritingnet" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" requirePermission="false"/>-->
  </configSections>
  <connectionStrings>
    <remove name="LocalMySqlServer" />
    <add name="LocalMySqlServer" connectionString=" Data Source=XXXX;Database=synergya_shoes;User ID=synergyaction;Password=XXX" />
    <add name="DefaultConnectionString" connectionString="Data Source=XXXXX;Database=synergya_shoes;User ID=synergyshoes12345;Password=XXXX" />
    <add name="hospitalConnectionString" connectionString="Data Source=XXXX;Database=synergya_shoes;User ID=synergyshoes12345;Password=XXXX" />
    <add name="hospitalConnectionString2" connectionString="Data Source=111.118.213.110;Database=synergya_shoes;User ID=synergyshoes12345;Password=password@1" />
  </connectionStrings>
  <!--<urlrewritingnet configSource="UrlRewriting.config"/>-->
  <system.web>
    <customErrors mode="Off" />
    <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
    <compilation debug="true" targetFramework="4.0">
      <codeSubDirectories>
        <add directoryName="CSharp"/>
      </codeSubDirectories>

      <assemblies>
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.RegularExpressions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
    <authentication mode="Forms">
      <forms loginUrl="~/Default.aspx" timeout="2880" />
    </authentication>
    <membership defaultProvider="AspNetKarigariNewSqlMembershipProvider">
      <providers>
        <clear />
        <add name="AspNetKarigariNewSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DefaultConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="KarigariNew" />
      </providers>
    </membership>
    <profile defaultProvider="AspNetKarigariNewSqlProfileProvider" enabled="true">
      <providers>
        <clear />
        <add name="AspNetKarigariNewSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="DefaultConnectionString" applicationName="KarigariNew" />
      </providers>
      <properties>
        <add name="FirstName" type="system.string" />
        <add name="LastName" type="System.string" />
        <add name="Gender" type="System.String" />
        <add name="DateOfBirth" type="System.DateTime" />
        <add name="PhoneNumber" type="System.String" />
        <add name="FaxNumber" type="System.String" />
        <add name="AlternateEmail" type="System.String" />
        <add name="Company" type="System.String" />
        <group name="ShippingAddress">
          <add name="Address1" type="System.String" />
          <add name="Address2" type="System.String" />
          <add name="City" type="System.String" />
          <add name="State" type="System.String" />
          <add name="CountryID" type="System.Int32" />
          <add name="ZipPostalCode" type="System.String" />
        </group>
        <group name="BillingAddress">
          <add name="Address1" type="System.String" />
          <add name="Address2" type="System.String" />
          <add name="City" type="System.String" />
          <add name="State" type="System.String" />
          <add name="CountryID" type="System.Int32" />
          <add name="ZipPostalCode" type="System.String" />
        </group>
        <group name="Preferences">
          <add name="ReceiveEmails" type="System.Boolean" defaultValue="True" />
          <add name="SubscribedToNewsletter" type="System.Boolean" defaultValue="True" />
          <add name="CurrencyId" type="System.Int32" defaultValue="12" />
        </group>
      </properties>
    </profile>
    <roleManager defaultProvider="AspNetKarigariNewSqlRoleProvider" enabled="true">
      <providers>
        <clear />
        <add name="AspNetKarigariNewSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnectionString" applicationName="KarigariNew" />
        <add name="AspNetKarigariNewWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="KarigariNew" />
      </providers>
    </roleManager>
    <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
      <controls>
        <!--<add tagPrefix="lbn" assembly="LightBox, Version=0.1.2006.0726, Culture=neutral, PublicKeyToken=69adabc7dfa9ff4c" namespace="LightBox"/>-->
      </controls>
    </pages>
    <httpModules>
      <!--<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>-->
    </httpModules>
  </system.web>
      <!-- <system.webServer>
        <directoryBrowse enabled="true"/>
        <defaultDocument>
            <files>
                <add value="Login.aspx"/>
            </files>
        </defaultDocument>
    </system.webServer>   -->
  <system.net>
  </system.net>
  <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
  <system.webServer>
    <modules>
      <!--<remove name="UrlRewriteModule"/>-->
      <!--<add name="UrlRewriteModule" preCondition="managedHandler" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>-->
    </modules>
    <!--<rewrite>
            <rules>
                <rule name="CanonicalHostNameRule1">
                    <match url="(.*)"/>
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.karigari\.in$" negate="true"/>
                    </conditions>
                    <action type="Redirect" url="http://www.karigari.in/{R:1}"/>
                </rule>
                <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
                    <match url="^product\.aspx$"/>
                    <conditions>
                        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true"/>
                        <add input="{QUERY_STRING}" pattern="^productid=([^=&amp;]+)&amp;name=([^=&amp;]+)$"/>
                    </conditions>
                    <action type="Redirect" url="product/{C:1}/{C:2}" appendQueryString="false"/>
                </rule>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^product/([^/]+)/([^/]+)/?$"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                    </conditions>
                    <action type="Rewrite" url="product.aspx?productid={R:1}&amp;name={R:2}"/>
                </rule>
            </rules>
            <outboundRules>
                <rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^(.*/)product\.aspx\?productid=([^=&amp;]+)&amp;(?:amp;)?name=([^=&amp;]+)$"/>
                    <action type="Rewrite" value="{R:1}product/{R:2}/{R:3}/"/>
                </rule>
            </outboundRules>
        </rewrite>-->
    <directoryBrowse enabled="true"/>
  </system.webServer>
  <location path="online">
    <system.web>
      <trust level="Full" />
    </system.web>
  </location>
</configuration>
Posted
Updated 16-Nov-12 2:18am
v3

The connection strings are a seperate collection, store it in your general settings to access it this way, or use the correct property ( I bet it's ConnectionStrings )
 
Share this answer
 
Comments
fjdiewornncalwe 16-Nov-12 9:55am    
+5. I bet you are right.
The reference to the connection string should be

ConfigurationManager.ConnectionStrings("connectionstringname");
 
Share this answer
 
You are using the wrong name: no appsetting with the name "SynergyShoes" exists.
 
Share this answer
 
Comments
DINESH K MAURYA 16-Nov-12 8:20am    
please change it "LocalMySqlServer" after that it shows same error msg.
[no name] 16-Nov-12 8:24am    
Solution 1 is where you are going wrong
DINESH K MAURYA 18-Nov-12 0:47am    
Dear all,

i have change connection string in sqlhelper class its ok but when i want to access from the webconfig file it is not access that string name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900