我有一个解决方案,两个 MVC 3 应用程序共享同一个 DAL libaray。每个应用程序都指向不同的数据库,它们的连接字符串存储在各自的 web.config 文件中。
将他们的连接字符串传递给 DAL 的最佳方法是什么?
从 MVC 控制器:
string _connectionString = WebConfigurationManager.ConnectionStrings["NexGenContext"].ToString();
// Changes???
QuestionDAL qd = new QuestionDAL();
var agency = qd.SearchAgencies(ori, name)
DAL 代码:
public IEnumerable<AgencyTerm> SearchAgencies(string ori, string name)
{
log.Debug("Executing: SearchAgencies(string ori, string name)");
List<AgencyTerm> agencies = new List<AgencyTerm>();
using (var conn = new SqlConnection(_connectionString))
{
var com = new SqlCommand();
com.Connection = conn;
com.CommandType = CommandType.StoredProcedure;
... etc....