本文介绍了更改nopCommerce的连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用nopCommerce,我需要删除settings.txt文件中的连接字符串并插入web.config文件。我该怎么办?

I am using nopCommerce and I need to remove the connection string in the settings.txt file and insert the web.config file. How can i do this?

推荐答案

只需执行两个步骤


  1. \中替换两个方法 LoadSettings SaveSettings \nopCommerce\库\Nop.Core\数据\DataSettingsManager.cs 。来自@Stephen Kiningham的链接的代码

  1. Replace two method LoadSettings and SaveSettings in \nopCommerce\Libraries\Nop.Core\Data\DataSettingsManager.cs. Code from link of @Stephen Kiningham

/// <summary>
/// Load settings
/// </summary>
/// <param name="filePath">File path; pass null to use default settings file path</param>
/// <returns></returns>
public virtual DataSettings LoadSettings(string filePath = null)
{            
    try
    {
        System.Configuration.Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
        return new DataSettings
        {
            DataConnectionString = webConfig.ConnectionStrings.ConnectionStrings["DefaultConnection"].ConnectionString,
            DataProvider = webConfig.ConnectionStrings.ConnectionStrings["DefaultConnection"].ProviderName
        };
    }
    catch (NullReferenceException)
    {
        return new DataSettings();
    }
}

/// <summary>
/// Save settings to a file
/// </summary>
/// <param name="settings"></param>
public virtual void SaveSettings(DataSettings settings)
{            
    if (null == settings) throw new ArgumentNullException("settings");

    System.Configuration.Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);

    webConfig.ConnectionStrings.ConnectionStrings["DefaultConnection"].ConnectionString = settings.DataConnectionString;
    webConfig.ConnectionStrings.ConnectionStrings["DefaultConnection"].ProviderName = settings.DataProvider;

    webConfig.Save();
}


  • 将连接字符串添加到Web配置web.config

  • Add connection string to your web config web.config

    <connectionStrings>
        <add name="DefaultConnection"
             connectionString=" Data Source=localhost;Initial Catalog=nopcommerce;Integrated Security=True;Persist Security Info=False"
             providerName="sqlserver">
        </add>
    </connectionStrings>
    


  • 这篇关于更改nopCommerce的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-25 10:15