From c9885abb67b4abbc73fa2220f6a9a837b50a8201 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Fri, 16 Nov 2018 21:20:58 -0800 Subject: [PATCH] fix for https://github.com/Microsoft/azuredatastudio/issues/3262 (#741) --- .../Profiler/ProfilerService.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs index ff28965d..516de2de 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Profiler/ProfilerService.cs @@ -146,8 +146,23 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler } else { - // create a new XEvent session and Profiler session - var xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo); + IXEventSession xeSession = null; + + // first check whether the session with the given name already exists. + // if so skip the creation part. An exception will be thrown if no session with given name can be found, + // and it can be ignored. + try + { + xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo); + } + catch { } + + if (xeSession == null) + { + // create a new XEvent session and Profiler session + xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo); + } + // start monitoring the profiler session monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);