VS2013更新4,MVC5,elmah.mvc(同ELMAH),VB/C#如何从代码访问elmah数据库?
下面的代码是标准的MVC模板的一部分上手,这是从内部代码建立我们的数据库连接的一部分访问SQL数据库:
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("DefaultConnection", throwIfV1Schema:=False)
Me.Configuration.LazyLoadingEnabled = True
End Sub
Public Shared Function Create() As ApplicationDbContext
Return New ApplicationDbContext()
End Function
我们还需要以下或在web.config中类似的东西:
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=mypc\SQLEXPRESS;Initial Catalog=mydb.DefaultContext;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="ElmahConnection" connectionString="Data Source=mypc\SQLEXPRESS;Initial Catalog=mydb.elmah;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
我加入了ELMAH连接字符串,因为它是有关我的问题。
然后在需要的每个位置添加以下定义,我们可以使用db访问数据库表。 <表名> ...:
Private db As New ApplicationDbContext
我想写一些方法与和上ELMAH数据表的工作,但它是一个不同的上下文的ApplicationContext。我不太明白我会写什么来建立与elmah表的连接,因为我没有真正设置它,它出现在elmah的dll中。