简体   繁体   English

将Kentico添加到ASP.NET MVC项目后连接失败

[英]Failure to to connect after Adding Kentico into ASP.NET MVC project

My ASP.NET MVC was in middle of development, so I researched about how to add media into the project and I come across the Kentico libraries.我的 ASP.NET MVC 正在开发中,所以我研究了如何将媒体添加到项目中,并且遇到了 Kentico 库。

And I tried to add Kentico.Content.Web.Mvc , Kentico.LanguagePack.English , Kentico.Libraries , Kentico.MediaLibrary and Kentico.Web.Mvc .我尝试添加Kentico.Content.Web.MvcKentico.LanguagePack.EnglishKentico.LibrariesKentico.MediaLibraryKentico.Web.Mvc

The website ran smoothly before, but after adding those packages, it then causes this error in the browser:该网站之前运行流畅,但添加这些包后,它会在浏览器中导致此错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server.与 SQL 服务器建立连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.验证实例名称是否正确,并且 SQL 服务器配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供者,错误:40 - 无法打开与 SQL 服务器的连接)

Description: An unhandled exception occurred during the execution of the current web request.说明:在执行当前 web 请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: CMS.DataEngine.ApplicationInitException: A network-related or instance-specific error occurred while establishing a connection to SQL Server.异常详细信息:CMS.DataEngine.ApplicationInitException:建立与 SQL 服务器的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.验证实例名称是否正确,并且 SQL 服务器配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供者,错误:40 - 无法打开与 SQL 服务器的连接)

Source Error:源错误:

An unhandled exception was generated during the execution of the current web request.当前 web 请求的执行过程中产生了一个未处理的异常。 Information regarding the origin and location of the exception can be identified using the exception stack trace below.可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

Stack Trace:堆栈跟踪:

[ApplicationInitException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. [ApplicationInitException:建立与 SQL 服务器的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.验证实例名称是否正确,并且 SQL 服务器配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)] (提供者:命名管道提供者,错误:40 - 无法打开与 SQL 服务器的连接)]

CMS.DataEngine.CMSApplication.ReportApplicationInitError(String message) +193 CMS.DataEngine.CMSApplication.ReportApplicationInitError(字符串消息)+193
CMS.DataEngine.CMSApplication.Init() +895 CMS.DataEngine.CMSApplication.Init() +895
Kentico.Web.Mvc.ApplicationHttpModule.HandleBeginRequest(Object sender, EventArgs e) +5 Kentico.Web.Mvc.ApplicationHttpModule.HandleBeginRequest(Object sender, EventArgs e) +5
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +144 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +144
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

I have tried to add a connection string into web.config :我试图将连接字符串添加到web.config

<configuration>
    <connectionStrings>
        ...
        <add name="CMSConnectionString" 
             connectionString="Persist Security Info=False;database=Kentico;server=myserver;user id=username;password=mypassword;Current Language=English;Connection Timeout=120;" />
    </connectionStrings>

Edited Global.asax.cs :编辑Global.asax.cs

protected void Application_Start()
{
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     // Enables and configures the selected Kentico ASP.NET MVC integration features
     ApplicationConfig.RegisterFeatures(ApplicationBuilder.Current);
}

Edited App_Start\RouteConfig.cs :编辑App_Start\RouteConfig.cs

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        // Maps routes to Kentico HTTP handlers.
        // Must be first, since some Kentico URLs may be matched by the default ASP.NET MVC routes,
        // which can result in pages being displayed without images.
        routes.Kentico().MapRoutes();

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

And created a new class named WebAssemblyInfo.cs in Properties :并在Properties中创建了一个名为WebAssemblyInfo.cs的新 class :

using CMS;

[assembly: AssemblyDiscoverable]
namespace WebApplication1.Properties
{
    public class WebAssemblyInfo
    {
    }
}

Adding those libraries makes several changes to your project as you've noted.正如您所指出的,添加这些库会对您的项目进行一些更改。 I'd suggest looking into your Kentico project's web.config file for the connection string and matching that.我建议查看您的 Kentico 项目的 web.config 文件中的连接字符串并进行匹配。 You'll have to make sure your MVC site still builds with the changes but copying the connection string from the Kentico project should resolve your issue (assuming your Kentico project still loads).您必须确保您的 MVC 站点仍然使用更改构建,但是从 Kentico 项目复制连接字符串应该可以解决您的问题(假设您的 Kentico 项目仍然加载)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM