How to download the DataBase from server to local?

Hi,

Here i am trying to do download the database file from server to my local, and uploading again to the server after updating my database.

I want to know is possible in unity?
I am using unity 5.3.4 personal edition.

If its possible, in first case how to download the database file from server to local and then how to upload it to server?

Thanks.

what do you want to achieve do with that ? gather all the database to the client and move it back it is not the right way. Let’s us know what do you want to do so we can help to solve it

While such a task is, technically, possible, as @juglarx said, it’s not the right way to do pretty much anything, and for several reasons

  1. The client shouldn’t be able to communicate directly with your database, as that opens your database up to many different forms of attacks
  2. There’s a lot of information you’re down/up -loading, a lot of unnecessary information. Better to get a query of what you need, and send an update of what you’re changing
  3. Depending on how you manage all that information, should you decide to ignore advice against such an action, could cause noticeable reductions in performance of your game or memory leaks

hey guys,

Here is my requirement,

I have a db file which is there in server, once i opened my unity scene(in editor or exe) that db file should download into local, later i should able to make changes in that db. Where i can add some details or modify or delete what ever i want.
Once i done with my scene i should able to upload this db to my server and replace my old db with this new one.

This process will repeat every time logged into that project.

Here client is gonna interact with the server directly, so i need to able to read the database from local as well as server, thats why i need to download and replace functionalities in this scene.

Thanks.

It sounds to me like you’re using a database to save the state of your game.

And effectively you want to be able to move the db file to and from the server for long term storage on the server…

I’m also assuming if you have more than 1 client/player, they each get their own ‘db file’… or at least I HOPE they do.

Then, sure, yeah… you technically can do this. You just need to create some interface on your server that allows access to upload or download these files.

BUT!

This sounds like the WORST method of saving the state of a game I’ve ever heard of. And I’ve heard some pretty bad methods of doing so.

Thanks for ytou valuable comment @lordofduct
I have some doubts in this process, because this is the new concept i have ever worked in unity.

  1. How can we save the unity scene state in db
  2. How can we download and upload the db file in sever.

I would say it’s simple, but I honestly cannot say that because that’s something that, while I have spent a lot of time conceptualizing, I haven’t tackled.
This is how I think you’d go about doing the task you’ve described:
On the server instance, you would serialize certain objects (whatever you chose) to a file that only the server has access to (stored locally) either at regular intervals (sort of like an auto-save) or when the server shuts down.
When the server loads up, it checks for this file and de-serializes it in such a way that any connecting clients also get this information.

No need to download or upload anything to a database.

By Db file, do really mean an XML file. When I want to load and save game data I use XML. and just like vedrit said, you don’t need a remote server to contact to read and write to. just read and write to the local hard drive.

I am not using the XML file, i am using the sqlite DB and i am using the json object in server to get the details from that DB.

Hi @schetty what do you need to do is implement a request/response services using http. Do not send the DB to the client

But requirement is like this.
I need to download the db to local and fetch the data from that then update and upload it to the server.
I have tried this code to download the sqlite db from server but its not downloading.Rather its throwing the error like this
UnauthorizedAccessException: Access to the path ‘local path’ is denied.

Here is my code: Can you please help me out?

using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
using System;
using System.Data;
using Mono.Data.Sqlite;

public class NewBehaviourScript : MonoBehaviour {

IEnumerator Start(){

WWW www = new WWW (url);
yield return www;

print (“Downloaded…,”);

string path = “File:///R:/Test/source/”;

File.WriteAllBytes (Application.dataPath+“/Test/”, www.bytes);:wink:

}

}

Thanks

Yeah, most web servers are configured to not allow the download of database files, and especially not upload (uploading in general is often heavily limited… that’d be a huge security hole otherwise). It isn’t often the client needs direct access to a database, so thusly web servers default to obscuring them.

Furthermore, if you have your file just sitting open on the internet like that, what’s to stop people from manipulating the db file all willy nilly.

As I said you need some interface on the server that allows access to upload and download the files. This could be a web service, or it could be a built in configuration of your web server itself (depending your webserver…), or several other means (though honestly a web service is often your best bet).

At this point this has nothing to do with the unity side of things, and all to do with your web server.

Thanks @lordofduct .
Any reference for this web server configuration?

Depends on your setup…

Do you administer your web server? Do you have anyone with IT experience with web servers? What web server do you use (2 big ones are Linux w/ Apache, and Windows w/ IIS… there are others, but I highly doubt you’re using them)? What approach do you want to take to it? What level of security do you want to attach to it? If you go with a web service, what platforms do you have available to you (node.js, asp.net, php, etc)?

We have a webserver admin and we are using linux webserver.
Mainly i want database download and upload functions. and we are using the json platform to sync with the server.

Talk to your admin.

They probably have their own ideas on what sort of approaches they’re willing to take to maintain security on the server.

Your problem boils down to downloading and uploading files. Uploading file is possible through http form, see: