As I'm using Entity Framwork Migrations, I'm runing it from the Up()
method in my inicial migration (Downloaded ELMAH-1.2-db-SQLServer.sql
file):
public override void Up()
{
string[] ElmahCommands = GetElmahStructureScript();
foreach (string line in ElmahCommands)
{
Sql(line);
}
//...
}
public static string[] GetElmahStructureScript()
{
string sqlConnectionString = new MyDbContext().Database.Connection.ConnectionString;
Regex regex = new Regex("^GO", RegexOptions.IgnoreCase | RegexOptions.Multiline);
string[] lines = regex.Split(ElmahScript);
return lines;
}
static string ElmahScript = @"
CREATE TABLE [dbo].[ELMAH_Error] ...
...
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON";
Atention: Remove the last "GO" statement! (I also removed the first part of the script, to check the compatibility version...)