2013-03-08 64 views
2

该问题可能是基本问题,如果是,请原谅我。我试图将我的Android应用连接到MSSQL服务器。我在下面的链接中使用了相同的代码。我已经按照这个链接所选择的答案用sqljdbc 4.3.0:与主机server.com/Db_name,端口1433的TCP/IP连接失败

com.mysql.jdbc.driver class not found exception

当我做这个,成功调试,但是当我在我的设备是三星Galaxy Y(姜饼)上运行它,它给我这个错误:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host server.com/Db_name, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.". 

任何帮助将不胜感激。

编辑:我在模拟器上运行它,它在文本视图中出现此错误。

回答

0

您有您的网址有问题android.os.NetworkOnMainThreadException,使用此URL格式:

jdbc:sqlserver://server.com\\Db_name; 
+0

你说了什么,我现在明白了。 com.microsoft.sqlserver.jdbc.SQLServerException:与主机server.com,名为实例Db_name的连接失败。错误: “Java.net.SocketTimeoutException”。验证服务器和实例名称,检查没有防火墙将UDP通信阻塞到端口1434,并且对于SQL Server 2005或更高版本,验证SQL Server Browser Service是否在主机上运行。我正在使用SQL Server 2005. – 2013-03-08 08:16:34

+0

看看这个问题:http://stackoverflow.com/questions/8911376/the-connection-to-the-host-server-failed-java – jlopez 2013-03-08 08:21:19

+0

我已经看到它。没什么帮助。 – 2013-03-08 08:34:58

1

你有此异常:

com.microsoft.sqlserver.jdbc.SQLServerException:The connection to the 
      host server.com, named instance Db_name has failed. 
Error:"Java.net.SocketTimeoutException". Verify the server and the instance names, 
      check that no firewall is blocking UDP traffic to port 1434, and for 
      SQL Server 2005 or later verify that the SQL Server Browser Service 
      is running on the host. 

基本上,你需要做什么异常消息说:

  1. 检查您是否使用了正确的服务器主机名。 (是否真的是“server.com”?)
  2. 检查您是否使用了正确的实例名称。 (是否真的是“Db_name”?)
  3. 检查是否没有防火墙阻止您从设备访问UDP端口1434。
  4. 检查SQL Server浏览器服务是否在“server.com”上运行(或者其它任何方式)。

一对夫妇的其他东西来试试你的设备上:

  • 检查,你可以做“server.com”(或其他)
  • 检查的DNS查询,你可以“平“中的‘server.com’主机(或其他)

基本上,有许多事情可能是错的,你需要有条不紊地消灭他们,直到找到概率的真正原因LEM。我们不能为你做到这一点。


I ran it on the emulator and it gives this error in the text view.

android.os.NetworkOnMainThreadException 

这是一个不同的问题。

这里的javadoc说什么:

"The exception that is thrown when an application attempts to perform a networking operation on its main thread.

This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged. See the document Designing for Responsiveness ."

总之,你不应该做网络的东西(包括说话的平台外的数据库)的主事件线程上...因为它可能会导致UI长时间锁定。

+0

我已经通过使用异步类(USing另一个线程)解决了第二个问题,但套接字超时异常仍然存在:( – 2013-03-08 11:55:32

+0

如何检查3?UDP端口的事情? – 2013-03-08 12:04:36

相关问题