views:

49

answers:

5

I have been reading that direct access to a SQL Server database over the Internet is insecure, so I am wondering what intermediary I can and should use between the client and the server. What are the best practices in terms of security and performance?

A: 

You can use with config.php. You must write db name, db user, db password, and host in config.php. Then you can use [?php require("config.php"); ?] in you page. Please change [ and ] to { and }.

skipsoft
+2  A: 

For direct access, you would have to use SSL on your connections, but generally, I wouldn't expose a database server to the internet. I would design my way around it, for example by creating web services in front of the db server.

k_b
A: 

You could just have a page in your web site's language (e.g. PHP, JSP, ASP, etc...) that queries the DB and returns the data you need in whatever format you need. For example:

If you're using jQuery:

from the client-side:

$.ajax({
  url: 'ajax/test.php',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});

Here, test.php would connect to the DB and query it and the result of test.php would be returned in the 'data' variable.

Chad
+2  A: 

Use an API - Application Programming Interface . This is a frontend door to the data you wish to expose. This means you will need to define what you expose and how.

For example, Stack Overflow does not allow their database to be accessed via anyone directly. BUT, they have allowed people to access certain parts of their database, via their Stack Apps API. What parts? they have exposed certains parts with their own API -> web url's that spit back data, based upon what you request. The results are in JSON format only (at the time of me posting this answer).

Here is a sample API method that exposes some of their database. (EDIT: hmm, none of the API links work ... the link i was trying to show was ...

http://api.stackoverflow.com/0.8/help/method?method=answers/{id}/

)

Now .. if you don't want to actually think about what data (eg DB tables, if you're using a Relational Database like Microsoft SQL Server or Oracle Sql Server) but want to expose the ENTIRE database .. just via the web ... then maybe you could look at using OData to stick in front of your DB, to expose it?

Another Edit: I was assuming you ment - allowing the public to access your DB .. not private. Otherwise, this should be on ServerFault.

Pure.Krome
+1  A: 

I'd written this lovely reply pertaining to web access to a SQL server, and then you go and update it stating you have a desktop app in place.

With that, as was said above, the best idea is to not expose a database server to the internet. If you absolutely have to, then there's a few possible solutions.

Implement some sort of VPN connection into the network. I had once instance where we had a large number of sites all connecting to a database server (and company network) via VPN. This kept the database server off of the internet, while still allowing a half decent access time to the information. This was for a retail environment with not a great deal of data throughput

Properly setup your firewalls and permissions on the server. This one should be done anyway. You could put the server behind a firewall, allowing access only on 1433, and only from a specific IP range (which i assume would be possible). This way, you can at least lower the amount of locations a possible attack could come from.

This could all be employed in addition to the APIs and services mentioned above.

fortheworld