我m working for a company that they use dll for connection string and i
尝试在ApplicationDbContext类中更改asp.net标识默认连接字符串,
我使用dll的连接类是这样的:
public class HRConnection
{
public string HR_con
{
get
{
return "server=192.168.1.21; database=HR; user=teamuser ; password=t123@456 ; connection timeout=30";
}
}
}
我ve tried to pass string like this , but it didn
工作
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
string HrConn = new HRConnection().HR_con;
public ApplicationDbContext()
: base(HrConn, throwIfV1Schema: false)
{
}
}
如何在代码中设置连接而不是从webconfig文件设置?
答案 0 :(得分:0)
我解决了这个问题
public ApplicationDbContext()
: base(new HRConnection().HR_con, throwIfV1Schema: false)
{
}
答案 1 :(得分:0)
首先尝试将硬编码字符串作为第一个参数传递给base。如果这样可行,那么我建议像这样定义你的字符串:
public class HRConnection
{
public readonly static string HR_con = "server=192.168.1.21; database=HR; user=teamuser ; password=t123@456 ; connection timeout=30";
}
并使用如下:
public ApplicationDbContext()
: base(HRConnection.HR_con, throwIfV1Schema: false)
{
}