Click here to Skip to main content
15,900,378 members
Home / Discussions / C#
   

C#

 
GeneralRe: Asynchronous Question Pin
Abhinav S4-Dec-09 3:33
Abhinav S4-Dec-09 3:33 
AnswerRe: Asynchronous Question Pin
Alan N4-Dec-09 3:32
Alan N4-Dec-09 3:32 
QuestionReportViewer VS 2008 Pin
staticv4-Dec-09 2:12
staticv4-Dec-09 2:12 
AnswerRe: ReportViewer VS 2008 Pin
Giorgi Dalakishvili4-Dec-09 3:37
mentorGiorgi Dalakishvili4-Dec-09 3:37 
QuestionAttaching to Membership Database Pin
froofy4-Dec-09 1:15
froofy4-Dec-09 1:15 
AnswerRe: Attaching to Membership Database Pin
Eddy Vluggen4-Dec-09 3:14
professionalEddy Vluggen4-Dec-09 3:14 
GeneralRe: Attaching to Membership Database Pin
froofy4-Dec-09 5:17
froofy4-Dec-09 5:17 
QuestionPerformance tip on extracting BLOB from database? Pin
Thomas ST3-Dec-09 23:38
Thomas ST3-Dec-09 23:38 
I am extracting 378000 BLOBS from a database.
This is mostly pdf,doc, and docx, but also some big wav,tiff,mpg, ++.

The code I'm currently using is a bit slow..

Does anyone have a tip on how to speed things up?

using (r2d2 = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) 
{
    if (!r2d2.HasRows)
        throw new Exception();

    DirectoryInfo dir = new DirectoryInfo(Path.Combine(_arbeider.KonverteringsAlternativer.RootOutputDirectory, "DOKUMENT"));
    if (!dir.Exists)
        dir.Create();

    while (r2d2.Read()) //only one row...
    {
        string filnavn = Convert.ToString(r2d2["filename"]);
        string sizeString = Convert.ToString(r2d2["size"]);
        int size = 0;
        bool sizeOK = int.TryParse(sizeString, out size);
        bool filnavnOK = false;

        try
        {
            new System.IO.FileInfo(filnavn);
            filnavnOK = true;
        }
        catch (ArgumentException erna)
        {
            throw new Exception("file not valid");
        }
        catch (System.IO.PathTooLongException)
        {
            throw new Exception("path not valid");
        }
        catch (System.Exception errrr)
        {
            throw new Exception("filename not supported", errrr);
        }

        if (filnavnOK && sizeOK && size > 0)
        {
            FileStream fs = null;
            BinaryWriter bw = null;

            //checking for duplicates
            if (_hashBrukteFilnavn.ContainsKey(filnavn))
                filnavn = Path.GetRandomFileName().Substring(0, 5) + filnavn; //duplicate
            
            _hashBrukteFilnavn[filnavn] = true;

            try
            {
                fs = new FileStream(Path.Combine(dir.FullName, filnavn), FileMode.OpenOrCreate, FileAccess.Write);
                bw = new BinaryWriter(fs);

                completePath = Path.Combine(dir.Name, filnavn);

                int startIndex = 0;
                int buffersize = 3072; //what is best? default network-packet size for mssql2008 is 4096(?)

                byte[] outbyte = new byte[buffersize];
                long retval = r2d2.GetBytes(2, startIndex, outbyte, 0, buffersize);

                //This loop is a bit slow.. How can I speed it up?
                while (retval == buffersize) 
                {
                    bw.Write(outbyte);
                    bw.Flush();
                    startIndex += buffersize;
                    retval = r2d2.GetBytes(2, startIndex, outbyte, 0, buffersize);
                }

                bw.Write(outbyte, 0, (int)retval);
            }
            catch (System.Exception err)
            {
                throw new Exception("error");
            }
            finally
            {
                if (bw != null)
                {
                    bw.Flush();
                    bw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                }
            }
        }
        else
            throw new Exception("file not valid");
    }
}

AnswerRe: Performance tip on extracting BLOB from database? Pin
Luc Pattyn4-Dec-09 1:49
sitebuilderLuc Pattyn4-Dec-09 1:49 
GeneralRe: Performance tip on extracting BLOB from database? Pin
Thomas ST7-Dec-09 2:43
Thomas ST7-Dec-09 2:43 
GeneralRe: Performance tip on extracting BLOB from database? Pin
Luc Pattyn7-Dec-09 3:15
sitebuilderLuc Pattyn7-Dec-09 3:15 
GeneralRe: Performance tip on extracting BLOB from database? Pin
Thomas ST7-Dec-09 7:23
Thomas ST7-Dec-09 7:23 
AnswerRe: Performance tip on extracting BLOB from database? Pin
PIEBALDconsult4-Dec-09 3:58
mvePIEBALDconsult4-Dec-09 3:58 
GeneralRe: Performance tip on extracting BLOB from database? Pin
Thomas ST7-Dec-09 1:23
Thomas ST7-Dec-09 1:23 
GeneralRe: Performance tip on extracting BLOB from database? Pin
PIEBALDconsult7-Dec-09 4:30
mvePIEBALDconsult7-Dec-09 4:30 
GeneralRe: Performance tip on extracting BLOB from database? Pin
Thomas ST7-Dec-09 7:27
Thomas ST7-Dec-09 7:27 
QuestionDataGridview Drag and drop Pin
anishkannan3-Dec-09 23:04
anishkannan3-Dec-09 23:04 
QuestionNeed sample code Pin
kankeyan3-Dec-09 20:12
kankeyan3-Dec-09 20:12 
AnswerRe: Need sample code Pin
dan!sh 3-Dec-09 20:49
professional dan!sh 3-Dec-09 20:49 
AnswerRe: Need sample code Pin
PIEBALDconsult4-Dec-09 4:00
mvePIEBALDconsult4-Dec-09 4:00 
GeneralC# and timer Pin
nsjn3-Dec-09 19:46
nsjn3-Dec-09 19:46 
GeneralRe: C# and timer Pin
The Man from U.N.C.L.E.3-Dec-09 22:14
The Man from U.N.C.L.E.3-Dec-09 22:14 
GeneralRe: C# and timer Pin
Corinna John3-Dec-09 22:18
Corinna John3-Dec-09 22:18 
GeneralRe: C# and timer Pin
PIEBALDconsult4-Dec-09 4:02
mvePIEBALDconsult4-Dec-09 4:02 
GeneralRe: C# and timer Pin
nsjn4-Dec-09 18:56
nsjn4-Dec-09 18:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.