Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从IIS 7.5上托管的ASP.NET MVC项目连接到mysql数据库_C#_Mysql_Asp.net Mvc_Iis_Deployment - Fatal编程技术网

C# 无法从IIS 7.5上托管的ASP.NET MVC项目连接到mysql数据库

C# 无法从IIS 7.5上托管的ASP.NET MVC项目连接到mysql数据库,c#,mysql,asp.net-mvc,iis,deployment,C#,Mysql,Asp.net Mvc,Iis,Deployment,我已经从Visual Studio 2015社区版开发了一个ASP.NET MVC应用程序,该应用程序使用.NET framework 4.5.2,MySql作为数据库。在开发机器上一切正常。但是,我在Windows 7 ultimate计算机上的IIS服务器上托管了该应用程序。我还安装了以下软件: MySQL.NET连接器6.9.8 MySQL服务器5.7.9 甚至我也在SmarterASP主机上托管了相同的东西。我也犯了同样的错误 我可以浏览这个网站。但只要有数据库连接,就会发生以下错误

我已经从Visual Studio 2015社区版开发了一个ASP.NET MVC应用程序,该应用程序使用.NET framework 4.5.2,MySql作为数据库。在开发机器上一切正常。但是,我在Windows 7 ultimate计算机上的IIS服务器上托管了该应用程序。我还安装了以下软件:

  • MySQL.NET连接器6.9.8
  • MySQL服务器5.7.9
  • 甚至我也在SmarterASP主机上托管了相同的东西。我也犯了同样的错误

    我可以浏览这个网站。但只要有数据库连接,就会发生以下错误

        [NullReferenceException: Object reference not set to an instance of an object.]
        MyApp.Models._Common.get_SystemConfigurations() +481
        ASP._Page_Views_Invoice__Invoice_cshtml.Execute() in h:\root\home\firnasz-001\www\site1\Views\Invoice\_Invoice.cshtml:23
        System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
        System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
        System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +90
        System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
        System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
        System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +277
        System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +91
        System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model) +32
        ASP._Page_Views_Invoice_Create_cshtml.Execute() in h:\root\home\firnasz-001\www\site1\Views\Invoice\Create.cshtml:7
        System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
        System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
        System.Web.WebPages.StartPage.RunPage() +17
        System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
        System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
        System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
        System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
        System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
        System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
       System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
       System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
       System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9711525
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
    
    [NullReferenceException:对象引用未设置为对象的实例。]
    MyApp.Models.\u Common.get\u SystemConfigurations()+481
    ASP.\u Page\u Views\u Invoice\u cshtml.Execute()位于h:\root\home\firnasz-001\www\site1\Views\Invoice\\u Invoice.cshtml:23中
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+197
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+105
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+90
    System.Web.Mvc.RazorView.RenderView(ViewContext、TextWriter、Object实例)+256
    System.Web.Mvc.buildmanager compiledview.Render(ViewContext、TextWriter)+107
    System.Web.Mvc.HtmlHelper.RenderPartialInternal(字符串partialViewName、ViewDataDictionary viewData、对象模型、TextWriter编写器、ViewEngineCollection ViewEngineCollection)+277
    System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper HtmlHelper,字符串partialViewName,对象模型,ViewDataDictionary viewData)+91
    System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper-HtmlHelper,字符串partialViewName,对象模型)+32
    ASP.\u页面\u视图\u发票\u创建\u cshtml.Execute()位于h:\root\home\firnasz-001\www\site1\Views\Invoice\Create.cshtml:7中
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+197
    System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+105
    System.Web.WebPages.StartPage.RunPage()+17
    System.Web.WebPages.StartPage.ExecutePageHierarchy()+64
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext-pageContext,TextWriter-writer,WebPageRenderingBase-startPage)+78
    System.Web.Mvc.RazorView.RenderView(ViewContext、TextWriter、Object实例)+256
    System.Web.Mvc.buildmanager compiledview.Render(ViewContext、TextWriter)+107
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)+291
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext ControllerContext,ActionResult ActionResult)+13
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1过滤器、Int32过滤器索引、ResultExecutingContext预文本、ControllerContext ControllerContext、ActionResult ActionResult)+56
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1过滤器、Int32过滤器索引、ResultExecutingContext预文本、ControllerContext ControllerContext、ActionResult ActionResult)+420
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList`1过滤器,ActionResult ActionResult)+52
    System.Web.Mvc.Async.c__显示类2B.b__1c()+173
    System.Web.Mvc.Async.c__显示Class21.b__1e(IAsyncResult asyncResult)+100
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+10
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+27
    System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+13
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+29
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+36
    System.Web.Mvc.Controller.b_u15(IAsyncResult asyncResult,Controller-Controller)+12
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+22
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+26
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
    System.Web.Mvc.MvcHandler.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)+21
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+29
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+49
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+28
    System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+9711525
    System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155
    
    下面是我的web.config

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <connectionStrings>
        <add name="DataContext" connectionString="server=localhost;username=root;password=****;database=myapp" providerName="MySql.Data.MySqlClient" />
      </connectionStrings>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2" />
      </system.web>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
          <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
        </providers>
      </entityFramework>
        <system.webServer>
            <directoryBrowse enabled="true" />
        </system.webServer>
    </configuration>
    
    
    
    如果有人需要进一步的信息,我会提供。请帮助我部署我的应用程序

    更新:以下是SystemConfiguration的get()

        private List<Configuration> _systemConfigurations;
        public List<Configuration> SystemConfigurations
        {
            get
            {
                DataContext dbContext = new DataContext();
                _systemConfigurations = dbContext.Configuration
                                            .Where(x => x.ConfigurationType.Title == _Config.CONFIG_TYPE_SYSTEM
                                                && x.Status == _Config.STATUS_ACTIVE).ToList();
    
                return _systemConfigurations;
            }
        }
    
    private List\u系统配置;
    公共列表系统配置
    {
    得到
    {
    DataContext dbContext=新的DataContext();
    _systemConfigurations=dbContext.Configuration
    .Where(x=>x.ConfigurationType.Title==\u Config.Config\u TYPE\u SYSTEM
    
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
    
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />