none
check server status before read or write? RRS feed

  • Question

  • Hello !

    i have an application on vb.net 2010 /Entity Framework / SQL Server 2008R2.

    In my application i have many read/write/update/delete  transaction.

    But , before i want to check if sql server is ready , if not i want to display en error message. I know that there is " Try... Catch"  block, but i want to know if there is something else to do this  , or i should use Try ..catch on every transaction?

    Thank you.

    Thursday, February 23, 2012 3:01 AM

Answers

  • Hi,

    I would suggest to first tell what is the exact error message you get to better make sure what means "not ready". IMO if the server is not reachable, you should always have a delay as it gives some time to the server for responding before giving up if no response is sent back...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Friday, February 24, 2012 1:36 PM

All replies

  • Hi dcode25,

    Welcome to MSDN Forum.

    How do you want to check if the sql server is ready? Do you mean you want to make sure whether the connection is open? If I understand correctly, you can just use an if statement to judge it. Based on the issue, if there's transaction in the code, any errors will lead the transaction roll back, you can see the exeption information by try catch statement.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us


    Friday, February 24, 2012 6:02 AM
    Moderator
  • ok

    but for example   i have this block ( is executed when i press a button):
    Try
    .....Read something from sql server
     
    Catch ex as exception
    .... Dispaly an error message
     
    end try
     
    i noticed that when the sql server is not ready on network , when i press the button for the first time the error message display very fast.If i try again to press the button ( and the server is again not ready) the error message display after some time .So , i need to know , when i do a  Read/Write/Update.... on entity framework , there is or not a delay before an exception occur?          Thank you!

    Friday, February 24, 2012 1:18 PM
  • Hi,

    I would suggest to first tell what is the exact error message you get to better make sure what means "not ready". IMO if the server is not reachable, you should always have a delay as it gives some time to the server for responding before giving up if no response is sent back...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Friday, February 24, 2012 1:36 PM
  • Maybe i was not clear.

    in my code   above ,  ....Display an error message - is just a MessageBox.Show("Error")

    I want to catch errors and this works , but when the server is not reachable , when i press the button for the first time , the message "Error" display instantly , if i try later to press the button ( the server is again not reachable) there is a delay before the message "Error". So why is this difference between first time and others?

    Friday, February 24, 2012 4:52 PM
  • Hi dcode25,

    Before execute command after pressing the button, I suggest you to make sure whether the database is reachable, just use an if statement to judge.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, February 27, 2012 7:54 AM
    Moderator