I m working for a company that they use dll for connection string and i
m正在尝试更改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";
}
}
}
i ve tried to pass string like this , but it didn
t工作
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
string HrConn = new HRConnection().HR_con;
public ApplicationDbContext()
: base(HrConn, throwIfV1Schema: false)
{
}
}
如何在代码中而不是在webconfig文件中设置连接?
我像这个一样解决了我的问题
public ApplicationDbContext()
: base(new HRConnection().HR_con, throwIfV1Schema: false)
{
}
首先尝试将硬编码字符串作为调用中的第一个参数传递给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)
{
}