Exemplo n.º 1
0
        /// <summary>
        /// The execute SQL.
        /// </summary>
        /// <param name="stproc">The stored procedure.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="read">The read.</param>
        /// <param name="token">The token.</param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task ExecuteSql(string stproc, Action <SqlParameterCollection> parameters, Action <SqlDataReader> read, CancellationToken token)
        {
            HomeHubEventSource.Log.MethodEnter();

            HomeHubEventSource.Log.FetchingData(stproc);

            using (var connection = new SqlConnection(this.connectionString))
            {
                await connection.OpenAsync(token);

                var command = connection.CreateCommand();
                command.CommandText = stproc;
                command.CommandType = System.Data.CommandType.StoredProcedure;

                parameters(command.Parameters);

                await SqlConnectionManager.ExecSafe(async() =>
                {
                    using (var reader = await command.ExecuteReaderAsync(token))
                    {
                        read(reader);
                    }
                });
            }

            HomeHubEventSource.Log.MethodLeave();
        }
Exemplo n.º 2
0
 public SqlDataLayer(string connectionString)
 {
     this.connectionManager = new SqlConnectionManager(connectionString);
     this.tokenSource       = new CancellationTokenSource();
 }