zepolyerf
zepolyerf

Reputation: 1188

How to connect to Google Cloud SQL from VB.NET?

I've created an app using VB.NET and I am planning on making a mobile app that will access the data created by the desktop app I made. So I'm thinking of uploading or publishing the database that the app is using somewhere on the web so that the mobile app I will be making can read that data.

I want to upload it on Google's Cloud SQL service. I am entirely new to this stuff so I did some search for tutorials. Everything that I found was very technical (at least on my pov) and are very hard to follow especially for beginners like me.

So how do I connect to Cloud SQL? Is it as simple as creating a MySqlConnection and setting the connection string's server to the IP Address of my instance of Cloud SQL?

Upvotes: 0

Views: 5292

Answers (1)

Kevin Malachowski
Kevin Malachowski

Reputation: 173

Connecting to a Cloud SQL database is very much like connecting to a local database. Like you mention you simply have to connect to the IP address of the remote instance (and port 3306, which is the usually default). In addition, you need to set up the firewall of the Cloud SQL instance to allow connections from the connecting machine. Here is the documentation page for connecting to the instance from the default MySQL client, and there are links on that page's sidebar that may be useful as well.

One thing to note, though, is that it is unsafe to allow your mobile app users connect directly to the database. If you allowed the users write access to the database there would be no way to prevent a bad actor from connecting and messing with the data you (and your users) have put there. Even if you arranged so that users only had read-access you still might leave yourself open for a DoS attack, preventing your real users from accessing your service.

You should consider running another server (i.e. on App Engine or Google Compute Engine, if you feel like sticking with Google products) to which your mobile users connect. This server would in turn connect to the Cloud SQL instance on the user's behalf. This would allow you to scale more easily by using something like memcache, plus gives you the flexibility of pre-processing data to reduce mobile bandwidth usage (which may or may not be useful, depending on the type of data you want to serve).

If you're really just serving read-only data (and you don't really need SQL to query it) you could consider uploading it to Google Cloud Storage and have your mobile users download it directly (you can make objects world-readable).

Upvotes: 1

Related Questions