2010/03/31

Response.WriteFile -"the server reset the connection"

Если использовать метод Response.WriteFile, то при отдача больших файлов, начиная с 5МБ, можно часто получить ошибку the server reset the connection.
Многие советуют переделать отдачу порциями типа:
try
{
// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
System.IO.FileAccess.Read,System.IO.FileShare.Read);


// Total bytes to read:
dataToRead = iStream.Length;

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

// Read the bytes.
while (dataToRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read the data in buffer.
length = iStream.Read(buffer, 0, 10000);

// Write the data to the current output stream.
Response.OutputStream.Write(buffer, 0, length);

// Flush the data to the HTML output.
Response.Flush();

buffer= new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
}
}
}
catch (Exception ex)
{
// Trap the error, if any.
Response.Write("Error : " + ex.Message);
}

Но есть более просто способ: всего-то использовать метод Response.TransmitFile

Response.TransmitFile() method sends the file to the client machine without loading it to the Application memory on the server, but Response.WriteFile() method loads the file that is being downloaded in the Application memory area of the server.


Непонятно зачем WriteFile нужен, если он грузит память да к тому же еще и не работает в некоторых случаях...

2010/03/26

Оптимизация индексов SQL Server

Нашел полезный скрипт:
DECLARE @dbid int
SELECT @dbid = db_id()
SELECT 'Table Name' = object_name(s.object_id), 'Index Name' =i.name, i.index_id,
'Total Writes' = user_updates, 'Total Reads' = user_seeks + user_scans + user_lookups,
'Difference' = user_updates - (user_seeks + user_scans + user_lookups)
FROM sys.dm_db_index_usage_stats AS s
INNER JOIN sys.indexes AS i
ON s.object_id = i.object_id
AND i.index_id = s.index_id
WHERE objectproperty(s.object_id,'IsUserTable') = 1
AND s.database_id = @dbid
AND user_updates > (user_seeks + user_scans + user_lookups)
ORDER BY 'Total Writes' DESC, 'Total Reads' ASC
А теперь ищем у кого большой Total Writes и нулевой Total Reads и нещадно удаляем.
Это нам разгружает нагрузку на веник и цпу при вставке - не пересчитываем индексы, которые не используются.

2010/03/24

IMAX 3D


Наконец-то открыл для себя мир 3D кино - сходил на Алису в IMAX.  Итог - не стоит оно того.

Если эффект очень сильный, когда объект как-бы прямо перед тобой,  то глаза начинают болеть секунд через 5. Поэтому в длином фильме эффект 3D делается не сильным, но глаза после половины фильма все равно устают и уже не могу дождаться конца :(

И в половине сцен начинаешь искать где же 3д, а не смотришь сам фильм.

Вообщем технология не развилась до комфортного уровня.

2010/03/12

Новые темы

Вау, у блоггера новые потрясающие темы!
Красота.
Осталось только наполнить сам блог красотой :)