开发者

Mysql external access

Is there a way to access a MySQL database with C# when external access is not enabled and I have no way to enable it? Some sort of PHP interface or somethin开发者_如何学运维g like that maybe? Thanks in advance.


You could write your own protocol on top of HTTP, (or on top of SOAP, on top of HTTP) but you need to ensure that you're not undermining the security by doing so....

<?php

$shared_secret = 'shhhh_s3cr3t!';
$qry=$_GET['qry'];
$remote_ip=_SERVER["REMOTE_ADDR"];
if (sha1($shared_secret . $qry , $remote_ip)!=$_GET['auth']) {
         header("HTTP/1.1 401 Unauthorized");
         print "not authorized!";
         exit;
} else {
   $dbh=mysql_connect($db_host, $db_user, $db_pass);
   if ($dbh===false) error_reply();
   $r=mysql_query($_GET['qry'], $dbh);
   if ($r===false) error_reply();
   $result=array();
   while ($result[]=mysql_fetch_assoc($r));
   print serialize($result);
   exit;
}

function error_reply()
{
   header("HTTP/1.1 503 Internal Server Error");
   print mysql_error();
}


Access to a MySQL DB is governed by whether the DB is configured to listen on a port from remote IP addresses, and whether the network allows traffic in on that port. Both the database and the firewall/network need configuring. Unless these are both configured to allow external access, you won't be able to reach the DB remotely with anything.

If these are set up and configured correctly, then you should be able to access the DB remotely somehow using a client library. I don't know whether C# has its own restrictions on connecting to a remote DB, if it does, then yes, you would need to find another way to connect that can be wrapped by C#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜