none
questions about Database. RRS feed

  • Question

  • there is one row in database table, and my application will read these data every 5s with timer. And also I need to update this row every 10 s.  

    so I am thinking about a situation, when I update this row while my application read data from it, what will be happen. whether have some errors from database or my code. this is just my doubt, because my next project will face this issue.

    so with the same issue, if I do not use database to store the data, I could use a xml file, so my application will read the xml file every 5s, and I will write data to these xml every 5s, and what is this situation will be happen?

    above are my company's two situations, if some has others ideas, please share me.

    one will read data and one will write data with one file or same row in database.


    I will mark any useful answer, so please answer my question more carefully and share me any useful blogs or documents. Thank you very much :)


    • Edited by GoyourGod Thursday, August 3, 2017 12:50 PM
    • Moved by Stanly Fan Monday, August 28, 2017 8:00 AM from windows form general
    Thursday, August 3, 2017 12:50 PM

All replies

  • If you read/write data to a database, it will usually make sure that multible users can access the data without conflicts.
    So if i understand what you are trying to do here, databases is the way to go.

    Files are not the same, with files you would have to handle access, i am pretty sure only one process can write to a file.
    I am not even sure you will be allowed to read from a file while someone is writing to it.

    Hope this answers your question.

    Thursday, August 3, 2017 1:34 PM
  • Hi friend,

    >>, it will usually make sure that multible users can access the data without conflicts.

    how to make sure this?

    >>I am not even sure you will be allowed to read from a file while someone is writing to it.

    this is our company's older scenario. so may be you will be worry. when I write a value to a file, and program will read the older value, so we have not care about this situation, we only to get that: when I write a value to this xml file, and program could read it without any problems.

    so I just know, in this situation which unexpected issue will be happen?

    Thank you very much, and also with database, what will be happen?


    I will mark any useful answer, so please answer my question more carefully and share me any useful blogs or documents. Thank you very much :)

    Saturday, August 5, 2017 3:25 AM
  • Hi,

    I'm not sure what will be happened before you meet it, as we do not know what will happen tomorrow, what we need to do is writing safe code, just like this format:

    using (SqlConnection conn = new SqlConnection(sqlCon)) 
    {
        using (SqlCommand cmd = new SqlCommand(sqlSelect, conn)) 
        {
            using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) 
            {
                //...
            }
        }
    }
    

    And about database and Xml, if you want to save massive amounts of data, I suggest you to use database instead of Xml, because the speed of reading with Xml is limited by its own file size, let's say, if a Xml file is 50M, then do some operation with this Xml file, it will consume time and consume CPU.

    And if you are interested in database and Xml, you can refer to the following document:

    XML and Databases

    Welcome to MSDN forum to ask questions if you later encounter any questions.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Monday, August 21, 2017 9:10 AM
    Wednesday, August 16, 2017 6:04 AM
  • Use database Transactions

    Depending on the locking mode / isolation level you use, your read operation will wait for the update to complete. 

    Files are considerably more "flaky" in this respect. 

     


    Regards, Phill W.

    Wednesday, August 16, 2017 10:28 AM