Reliable connection to Azure SQL Database

I am developing a C # application that stores data in an Azure SQL database.

As you probably know, the Azure SQL database is located somewhere on the Internet. Not on a local network (but this question is also suitable for a reliable network such as LAN).

I noticed that from time to time I get errors such as “Connection closed” (or other network errors). It is very easy to imitate this with Clumsy . The causes of these errors are poor network conditions.

So, my first idea to solve this problem is to try again. When I get this error, I just try again, and then it works well. Like magic.

This may be the solution to the problem, but open up another kind of problem. Not all situations are good with this solution. I will explain:

I separate scripts for two types:

  • Cannot retry, such as SELECT or DELETE. Retrying will have the same expected result. So, with such problems - my solution works fine!
  • Insert or Refresh - retrying will damage the information.

I will concentrate point number 2 . For example, suppose I have:

  • User table. The columns in this table are: ID, UserName, Credits.
  • A saving procedure that forces the user (by user ID) to pay for some of his loans.

Saved Pay procedure:

UPDATE tblUsers SET [Credits] -= @requestedCredits WHERE ID=@ID

Calling SP is a tricky issue:

  • If this works without problems, we are fine.
  • , , . , !

, "" .

, :

, "VersionID" . SP :

UPDATE tblUsers SET [Credits] -= @requestedCredits, VersionId=NEWID() WHERE ID=@ID AND VersionID=@OldVersionId

, Pay(), (Random GUID), GUID , ( , ). VersionId , , .

, , . , , Pay() , , ( ).

?

+4
2

, SQL- // (.. -Azure) SQL Azure.

:

  • , Azure, API

    API , Azure WebApp VM. API SQL Azure.

    SQL - ​​ , HTTP. , .

  • -

    , #, . - .

  • Azure VPN- - . .

+1

. , . " ", . , -, -, - .

, . , , .

+1

Source: https://habr.com/ru/post/1624592/


All Articles