public static void ExecuteReader(string procedureName, SqlParams parameters, CommandBehavior behavior, Action <SqlDataReader> readerCallback) { using (SqlConnection connection = GetNewSqlConnection()) { connection.Open(); ExecuteReader(connection, procedureName, parameters, behavior, readerCallback); connection.Close(); //try/finally to close not needed as connection.Dispose closes the connection at end of using block. } }
public static DataTable GetDatatable(string procedureName, SqlParams sqlParams, string datatableName) { DataTable datatable = new DataTable(datatableName); using (SqlConnection connection = GetNewSqlConnection()) { SqlCommand command = new SqlCommand(procedureName); command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 320; command.Connection = connection; command.Parameters.AddRange(sqlParams); SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(datatable); } return(datatable); }
/// <summary> /// Only used for generating reports with Aspose.Cells. This is not to be used to populate any site content. /// </summary> /// <param name="procedureName"></param> /// <param name="datasetName"></param> /// <param name="srcTable"></param> /// <returns></returns> public static DataSet GetDataset(string procedureName, SqlParams sqlParams, string datasetName, params string[] tableNames) { DataSet dataset = new DataSet(datasetName); using (SqlConnection connection = GetNewSqlConnection()) { SqlCommand command = new SqlCommand(procedureName); command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 320; command.Connection = connection; command.Parameters.AddRange(sqlParams); SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(dataset); int i = 0; foreach (string tableName in tableNames) { dataset.Tables[i++].TableName = tableName; } } return(dataset); }
public static void ExecuteReader(SqlConnection openConnection, string procedureName, SqlParams parameters, CommandBehavior behavior, Action <SqlDataReader> readerCallback) { using (SqlCommand command = new SqlCommand(procedureName, openConnection)) { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 180; command.Parameters.AddRange(parameters ?? new SqlParams()); SqlDataReader reader = command.ExecuteReader(behavior); try { readerCallback(reader); } finally { if (reader != null) { reader.Close(); } } //Close reader even if exception thrown } //dispose the command even if exception thrown }
public static void ExecuteReader(SqlConnection openConnection, string procedureName, SqlParams parameters, Action <SqlDataReader> readerCallback) { ExecuteReader(openConnection, procedureName, parameters, CommandBehavior.Default, readerCallback); }