Tony Wolf
Tony Wolf

Reputation: 3

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.

And I tried to add Kentico.Content.Web.Mvc, Kentico.LanguagePack.English, Kentico.Libraries, Kentico.MediaLibrary and Kentico.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. 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

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: CMS.DataEngine.ApplicationInitException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Source Error:

An unhandled exception was generated during the execution of the current web request. 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. 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]

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

I have tried to add a connection string into 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:

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:

    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:

using CMS;

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

Upvotes: 0

Views: 860

Answers (1)

Brenden Kehren
Brenden Kehren

Reputation: 6117

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. 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).

Upvotes: 0

Related Questions