我刚刚设置了MiniProfiler 以将结果保存到 SQL Azure,这相当容易。我们使用MiniProfiler.MVC3 来处理所有接线,如here 所述。
表创建脚本嵌入到带有SqlServerStorage.TableCreationScript 静态字段的程序集中,因此您可以使用它,但在深入研究代码时,我发现最新的开发分支通过添加一些索引略微增强了脚本。表结构在其他方面保持不变,因此它仍然适用于nuget 上提供的最新包。
在将here is direct link 写入最新的表创建脚本时。
之后,您唯一需要做的就是设置 MiniProfiler 以通过单行代码使用 SQL:
MiniProfiler.Settings.Storage = new SqlServerStorage("<your connection string>");
如果您不使用 SQL Azure,就是这样,但是当我们尝试在 Azure 中使用它时,我发现了一个问题。分析尝试保存时,我收到以下异常(谢谢ELMAH):
System.Data.SqlClient.SqlException
此版本的 SQL Server 不支持没有聚集索引的表。请创建聚集索引,然后重试。
为了解决这个问题,我必须在MiniProfilers 表中添加一个额外的(未使用的)列。以下是相关创建表脚本的开头:
create table MiniProfilers
(
RowId integer not null identity constraint PK_MiniProfilers primary key clustered, -- Need a clustered primary key for SQL azure
Id uniqueidentifier not null,
Name nvarchar(200) not null,
由于 Guid Id 列不再是主键,我添加了一个额外的索引以确保查找仍然快速:
create unique nonclustered index IX_MiniProfilers_Id on MiniProfilers (Id)
希望对您有所帮助。
更新
支持 SQL Azure 的更改已作为 Pull Request 提供并被接受。谢谢Jarrod。