Example #1
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            HandleConnectionNull();

            CreateSqlCommand();

            CreateSqlParamList();

            var dataSet = new DataSet();

            using (_wrappedSqlConnection = new SqlConnection(Connection.ConnectionString))
            {
                using (_wrappedSqlCommand)
                {
                    _wrappedSqlCommand.Connection = _wrappedSqlConnection;
                    _wrappedSqlConnection.Open();

                    var virtModel = new VirtSqlRpcModel(CommandText);

                    var sw = Stopwatch.StartNew();

                    using (var reader = _wrappedSqlCommand.ExecuteReader())
                    {
                        do
                        {
                            var schema = CreateSchemaTable(reader);

                            var data = CreateAndLoadDataTable(reader);

                            AddResultToVirtModel(virtModel, data, schema);

                            dataSet.Tables.Add(data);
                        } while (!reader.IsClosed);
                    }

                    MapOutParametersAndReturnValue(virtModel);

                    sw.Stop();

                    virtModel.DelayMs = sw.ElapsedMilliseconds;

                    ServiceVirtMountebankPublisher.AddRecordedCommand(virtModel);
                }
            }

            return(dataSet.CreateDataReader());
        }
Example #2
0
        public override int ExecuteNonQuery()
        {
            HandleConnectionNull();

            CreateSqlCommand();

            CreateSqlParamList();

            int rowsAffected = 0;

            using (_wrappedSqlConnection = new SqlConnection(Connection.ConnectionString))
            {
                using (_wrappedSqlCommand)
                {
                    _wrappedSqlCommand.Connection = _wrappedSqlConnection;
                    _wrappedSqlConnection.Open();

                    var sw = Stopwatch.StartNew();

                    rowsAffected = _wrappedSqlCommand.ExecuteNonQuery();

                    sw.Stop();

                    var virtModel = new VirtSqlRpcModel(CommandText)
                    {
                        DelayMs      = sw.ElapsedMilliseconds,
                        RowsAffected = rowsAffected
                    };

                    MapOutParametersAndReturnValue(virtModel);

                    ServiceVirtMountebankPublisher.AddRecordedCommand(virtModel);
                }
            }

            return(rowsAffected);
        }