0

Can I save my data (after inputs from client computer) into my server database while there's a internet connection and when there's no internet connection the data will be saved on client computer and when the internet connection online again, the data will be sent to my server database ( or using a button click )

Is that possible?

I'm using visual studio c# thanks

SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["conn"].ConnectionString);

i'm planning

try{
  con.Open()
  //save to database
} 
catch
{
  //save to local
}

while it was risky if i get error, it will moved to catch too

and is that possible to make session / cookies last forever?

Stephen Reindl
  • 5,659
  • 2
  • 34
  • 38
deni augtaviano
  • 61
  • 1
  • 10
  • hi, thanks for reply, do you have any example? in my case, i only want to save the last transaction while there's trouble on connection, and only 1 insert command – deni augtaviano Oct 04 '16 at 13:47
  • great, thanks, i'll try using xml, because i'm not familiar with json.. – deni augtaviano Oct 04 '16 at 14:02
  • I fear the comments so far have been misleading since it is **not** possible to store some data on your **client** in the ASP.NET code. There are ways to store data on the client in case the connection to the server is not available, but these involve the [HTML5 Local Storage](http://www.w3schools.com/html/html5_webstorage.asp) and must be used from code which is executed in the client's browser (JavaScript). – fknx Oct 04 '16 at 14:18
  • @fknx oh dear....you are so right. I was thinking purely from a dotnet mindset and wasn't even thinking about it being asp.net. Doh. More coffee is needed. – Sean Lange Oct 04 '16 at 14:22
  • awww dang, i tought i could just save at client c: or something – deni augtaviano Oct 04 '16 at 14:44
  • could help you out http://stackoverflow.com/questions/1941928/best-way-to-store-data-locally-in-net-c – Rojalin Sahoo Oct 04 '16 at 15:43
  • @deniaugtaviano maybe you could store it in the session? – Paul Zahra Oct 05 '16 at 11:56
  • session has time limit ( as i know ) i'm affraid it will be gone if no connection too long, not sure tough – deni augtaviano Oct 05 '16 at 14:53
  • I updated your grammar – Stephen Reindl Oct 07 '16 at 14:38

1 Answers1

0

You forget the main thing - Asp.Net is on the server. Your try-catch is on the server. Code execution is on the client. If client does not have connection, it will not be able to contact the server to even let the server know that there is no connection and it needs to save locally. Also session is also on the server, not on the client.

You will need to use local browser storage to save user input. And then sync the data to the server when there is a connection. There are a number of articles about how to get offline application running. Quick search for "javascript offline application" gave me a range of articles:

I recommend review these articles to get general direction of what you need implemented. Unfortunately offline mode is not possible to implement purely with Asp.Net, you'll have to use other technologies.

Community
  • 1
  • 1
trailmax
  • 34,305
  • 22
  • 140
  • 234