Corrected your code:
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms, int commandTimeout)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
cmd.CommandTimeout = commandTimeout;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
{
if(parm.SqlValue == null) {parm.SqlValue = DBNull.Value; }
cmd.Parameters.Add(parm);
}
}
}
You had set the same value as the connection timeout which is usually 15 seconds and may be enough to make a connection to the database but not for a longer SQL statement call.
Hope this clears your issue. I would make the value for the SqlCommand.CommandTimeout configurable via applications settings.
Best Regards,
-MRB