[英]The TCP/IP connection to the host localhost, port 1433 has failed
[英]The TCP/IP connection to host server.com/Db_name, port 1433 has failed
这个问题可能是一个基本的问题,如果是,请原谅。 我正在尝试将我的Android应用程序连接到MSSQL Server 。 我在下面的链接中的问题中使用了相同的代码。 我根据此链接中选择的答案使用了sqljdbc 4.3.0:
当我这样做时,它将成功调试,但是当我在三星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.".
任何帮助将不胜感激。
编辑:我在模拟器上运行它,它在文本视图中给出此错误。
android.os.NetworkOnMainThreadException
您遇到了以下异常:
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.
基本上,您需要按照异常消息的说明进行操作:
在您的设备上尝试其他几件事:
基本上,有很多事情可能是错误的,您需要有条不紊地消除它们,直到找到问题的真正原因。 我们不能为您做到这一点。
我在模拟器上运行它,并在文本视图中给出了此错误。
android.os.NetworkOnMainThreadException
这是一个不同的问题。
这是javadoc所说的:
“应用程序尝试在其主线程上执行网络操作时引发的异常。
仅针对面向Honeycomb SDK或更高版本的应用程序抛出此错误。 允许以较早版本的SDK为目标的应用程序在其主事件循环线程上进行联网,但不建议这样做。 请参阅文档“ 响应能力设计 ”。”
简而言之,您不应该在主事件线程上进行网络工作(包括与跨平台数据库进行对话)...因为这很可能导致UI锁定较长时间。
您的网址有问题,请使用以下网址格式:
jdbc:sqlserver://server.com\\Db_name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.