Question

If i use local database, say MySQL, it works perfect on simulator and emulator but for real device, localhost won't do, So i tried online database hosting.

When using online hosting from www.freemysqlhosting.net, i had setup the database in my database development perspective in Eclipse using the provided id and password, so it worked well on my simulator, emulator and real device that was connected to the same network as that system on which that database was setup, but for any anonymous device,it failed!

Then i tried with sqllite, again it worked with simulator and emulator but for real device,it showed UNRESPONSIVE_HOST error.

My question is: if i want to develop an app using IBM Worklight that uses some database and want to distribute it, how can i do it?

Was it helpful?

Solution 3

Your problem is not with the SQL server it is with the connection between the device and the Worklight server. You need to be able to connect from the device to the Worklight server. Open a browser on the device and point it to the Worklight console and see that you can access it.

OTHER TIPS

It would have been far far more helpful if you'd just provide the error log from LogCat...

When using Android, it is a good practice to not use localhost, instead to use the actual IP address. See this question: IBM Worklight - Unable to connect to database when using IP address instead of localhost

MySQL is a server like any other server; if you want to use it outside of your private local network, then you simply need to open it to incoming connections from the public Internet. This is not something a developer needs to fuss around with, that's what IT departments are for. So google and see how to open your network.

This sounds as though you are trying to access a database directly from your device. Is that the case?

I would strongly recommend using Worklight Adapters here. So the pattern goes:

 App on Device ---> Adapter ---> Database

In that pattern the responsibility for getting from Device to the Adapter lies with Worklight and hence should be completely unaffected by whether it's a real device or an emulated one, and should also be independent of what particular database you are using or where it it.

The hop from Adapter to Database is something you can set up and test without even having an deployed anywhere. Just use the test environment in Eclipse to call adapter methods.

Why not go from device directly to database? In general that's a really bad security pattern, you're effectively putting data you care about in a very hackable place. Also it will not scale well to large numbers of users: connecting directly from the device means that effectively every user has their own connection, going via the adapter users share a controllable number of connections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top