在web.config中查找连接字符串时,空引用异常 [英] Null reference exception when looking up connection string in web.config

查看:65
本文介绍了在web.config中查找连接字符串时,空引用异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有

发生以下错误.


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




以下是web.config代码





below is web.config code


<?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>

推荐答案

" negate="true"/> </conditions> <action type="Redirect" url="http://www.karigari.in/{R:1}"/> </rule> <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^product\.aspx
" negate="true"/> </conditions> <action type="Redirect" url="http://www.karigari.in/{R:1}"/> </rule> <rule name="RedirectUserFriendlyURL1" stopProcessing="true"> <match url="^product\.aspx


"/> <条件> <add input="{REQUEST_METHOD}" pattern="^POST
"/> <conditions> <add input="{REQUEST_METHOD}" pattern="^POST


" negate="true"/> <add input="{QUERY_STRING}" pattern="^productid=([^=&amp;]+)&amp;name=([^=&amp;]+)
" negate="true"/> <add input="{QUERY_STRING}" pattern="^productid=([^=&amp;]+)&amp;name=([^=&amp;]+)


这篇关于在web.config中查找连接字符串时,空引用异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆