Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. IO problem

IO problem

Scheduled Pinned Locked Moved C#
databasexmlhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sianatia
    wrote on last edited by
    #1

    Hi I have designed an application which creates and uses an encoded XML file as its database.Some times overnothng this file gets damaged. I put a backup service for this app to check the file every 20 seconds and if it finds errors in the file it will restore the backup.The point is sometimes althought the file is broken ,the backup service finds this file as correct.also the program continues working with the file untill it gets closed.After closing the program the problems raise I face a big loss in data. Could anyone tell me what the problem is and why before closing the app the file seems to be correct but after closing the app file gets corrupted. Thanks

    C 1 Reply Last reply
    0
    • S sianatia

      Hi I have designed an application which creates and uses an encoded XML file as its database.Some times overnothng this file gets damaged. I put a backup service for this app to check the file every 20 seconds and if it finds errors in the file it will restore the backup.The point is sometimes althought the file is broken ,the backup service finds this file as correct.also the program continues working with the file untill it gets closed.After closing the program the problems raise I face a big loss in data. Could anyone tell me what the problem is and why before closing the app the file seems to be correct but after closing the app file gets corrupted. Thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Yes, the problem is bugs in your code. We can't really say more without seeing the code.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      S 1 Reply Last reply
      0
      • C Christian Graus

        Yes, the problem is bugs in your code. We can't really say more without seeing the code.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        S Offline
        S Offline
        sianatia
        wrote on last edited by
        #3

        Hi, This is my code: System.IO.FileStream file=System.IO.File.OpenWrite(_fileName);//file to be written System.IO.MemoryStream ms=new System.IO.MemoryStream();//in memory stream for some puspose dataset.WriteXml(ms);//write dataset into memory stream ms.Position=0; byte[] buffer=new byte[ms.Length];//create buffer ms.Position=0; ms.Read(buffer,0,buffer.Length);//read memory stream ms.Close(); file.Position=0; file.SetLength(0); //flush the main file buffer=System.Text.Encoding.UTF8.GetBytes(Encrypter.EncryptData(System.Text.Encoding.UTF8.GetString(buffer)));//encrypt data file.Write(buffer,0,buffer.Length);//write dato into main file file.Close();//close file Just one process can write on main file,other processes like backup process may read this file.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups