private StatusErrorCode SetTraceStatus(TraceStatus status) { if (traceId == 0) { throw new NotInitializedProfilerException(); } StatusErrorCode code = StatusErrorCode.IsInvalid; try { SqlCommand cmd = MsSqlUtil.NewStoredProcedure("sp_trace_setstatus"); MsSqlUtil.AddInParam(cmd, "@traceid", traceId); MsSqlUtil.AddInParam(cmd, "@status", status); code = (StatusErrorCode)MsSqlUtil.ExecuteStoredProcedure(cmd, connInfo.CreateConnectionObject()); if (code == StatusErrorCode.NoError) { this.traceStatus = status; } } catch (SqlException exc) { if (exc.Message.Contains("Could not find the requested trace")) { return(StatusErrorCode.TraceIsInvalid); } //throw; } return(code); }
private CreateTraceErrorCode InitTrace(TraceOptions traceOptions, string traceFilePath, int?maxFileSize, DateTime?stopTime) { SqlCommand cmd = MsSqlUtil.NewStoredProcedure("sp_trace_create"); SqlParameter tId = MsSqlUtil.AddOutParam(cmd, "@traceid", traceId); MsSqlUtil.AddInParam(cmd, "@options", (int)traceOptions); MsSqlUtil.AddInParam(cmd, "@tracefile", traceFilePath); if (maxFileSize != null) { MsSqlUtil.AddInParam(cmd, "@maxfilesize", maxFileSize); } if (stopTime != null) { MsSqlUtil.AddInParam(cmd, "@stoptime", stopTime); } int result = MsSqlUtil.ExecuteStoredProcedure(cmd, connInfo.CreateConnectionObject()); traceId = Convert.ToInt32(tId.Value); this.traceFilePath = traceFilePath + ".trc"; //Add filter to filter profiler stored procedures AddTraceFilter(TraceField.ApplicationName, LogicalOperator.AND, ComparisonOperator.NotEqual, connInfo.ApplicationName); return((CreateTraceErrorCode)result); }
public AddTraceFilterErrorCode AddTraceFilter <T>(TraceField traceField, LogicalOperator logicalOp, ComparisonOperator compOp, T value) { if (traceId == 0) { throw new NotInitializedProfilerException(); } SqlCommand cmd = MsSqlUtil.NewStoredProcedure("sp_trace_setfilter"); MsSqlUtil.AddInParam(cmd, "@traceid", traceId); MsSqlUtil.AddInParam(cmd, "@columnid", (int)traceField); MsSqlUtil.AddInParam(cmd, "@logical_operator", (int)logicalOp); MsSqlUtil.AddInParam(cmd, "@comparison_operator", (int)compOp); MsSqlUtil.AddInParam(cmd, "@value", value); return((AddTraceFilterErrorCode)MsSqlUtil.ExecuteStoredProcedure(cmd, connInfo.CreateConnectionObject())); }
public AddTraceEventErrorCode AddTraceEvent(TraceEvent traceEvent, params TraceField[] traceFields) { if (traceId == 0) { throw new NotInitializedProfilerException(); } foreach (TraceField field in traceFields) { SqlCommand cmd = MsSqlUtil.NewStoredProcedure("sp_trace_setevent"); MsSqlUtil.AddInParam(cmd, "@traceid", traceId); MsSqlUtil.AddInParam(cmd, "@eventid", (int)traceEvent); MsSqlUtil.AddInParam(cmd, "@columnid", (int)field); MsSqlUtil.AddInParam(cmd, "@on", true); MsSqlUtil.ExecuteStoredProcedure(cmd, connInfo.CreateConnectionObject()); if (!this.traceFields.Contains(field.ToString())) { this.traceFields.Add(field.ToString()); } } return(AddTraceEventErrorCode.NoError); }