将android连接到远程sqlserver
我想连接到SQL Server远程数据库,但我无法在Android中创建新连接,尽管我可以通过具有相同代码的Java应用程序进行连接。 DriverManager.getConnection()
引发异常。这里是我的代码将android连接到远程sqlserver
public DatabaseManipulation()
{
URL=String.format(URL,localDatabaseName);
Connect();
}
public void Connect() {
try {
connection = DriverManager.getConnection(URL,
DATABASE_USERNAME, DATABASE_PASSWORD);
statement=connection.createStatement();
} catch(Exception e) {
Log.d("con",e.getMessage);
}
}
例外:
"The TCP/IP connection to the host 192.168.100.23, port 1433 has failed. Error: "/192.168.100.23:1433 - Network is unreachable. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."."
当两个或多个SQL服务器都通过网络连接它们在使用TCP/IP的所有通信。 SQL Server安装的默认端口是1433.可以通过SQL Server配置管理器更改此端口。应该启用TCP/IP连接SQL Server。
进入所有程序>>的Microsoft SQL Server 2008 >>配置工具>> SQL Server配置管理>>选择TCP/IP
我已检查它是。正如我告诉我可以连接抛出一个Java应用程序与确切的代码,但我有问题在Android中。 – Alireza 2014-08-28 20:49:11
192.168.100.23是不是从互联网访问的私网IP地址。您的设备是否位于同一网络上?顺便说一下,从移动设备直接访问远程数据库会带来很多安全和体系结构问题。你有没有考虑在你的数据库前面有一项服务来支持移动应用程序? – wdosanjos 2014-08-28 06:04:17
是设备在同一个网络中。我可以连接到另一台PC上的Java应用程序,但没有问题,但Android不起作用。 – Alireza 2014-08-28 06:13:40
您的应用程序是否具有在AndroidManifest.xml中设置的网络访问权限? (''使用权限的android:name =“android.permission.INTERNET”/>') – wdosanjos 2014-08-28 06:17:25