#StackBounty: #c# #linqpad How can I set a timeout om my query on LinqPad on ExecuteQueryDynamic?

Bounty: 50

How can I set a timeout om my query on LinqPad on ExecuteQueryDynamic?

Util.CurrentDataContext.ExecuteQueryDynamic($"SELECT count(*) FROM MyDb.dbo.{viewName}");

I would like to use this timeout to detect the too slow views. For each view I request a count but when my count take too much time I just stop it and count the next one.

Here is my full LINQPad code

void Main()
    // In case of error "There is already an open DataReader associated with this Command which must be closed first."
    // https://stackoverflow.com/q/6062192/196526
    // Add MultipleActiveResultSets=true to connection string. 

    var biewsCount = b.V_sysobjects.Where(v => v.Type == "V").Count();
    var bViewsDetail = Util.OnDemand<List<SysObject>>("Get Views Detail", () => GetViewsDetail("b", b.V_sysobjects.Where(v => v.Type == "V").Select(v => v.Name).ToList()));

public List<SysObject> GetViewsDetail(string database, List<string> objectNames)
    var result = new List<SysObject>();
    foreach (var name in objectNames)
        // I should add a timeout stuff here or before
        var count = (int)Util.CurrentDataContext.ExecuteQueryDynamic($"SELECT count(*) FROM {database}.dbo.{name}").Select(y => y).Single();
        Console.Write($" {count}n");
        result.Add(new SysObject
            Database = database,
            ObjectName = name,
            Rows = count
    return result;

public class SysObject
    public string Database { get; set; }
    public string ObjectName { get; set; }
    public string ObjectType { get; set; }
    public string IndexName { get; set; }
    public long Rows { get; set; }
    public long? TotalPages { get; set; }
    public long? UsedPages { get; set; }
    public long? DataPages { get; set; }
    public long? TotalSpaceMB { get; set; }
    public long? UsedSpaceMB { get; set; }
    public long? DataSpaceMB { get; set; }

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.