[英]The TCP/IP connection to host server.com/Db_name, port 1433 has failed
The question might be a basic one and if it is, pardon me. 这个问题可能是一个基本的问题,如果是,请原谅。 I'm trying to connect my Android app to MSSQL Server .
我正在尝试将我的Android应用程序连接到MSSQL Server 。 I used the same code in my question in the link below.
我在下面的链接中的问题中使用了相同的代码。 I have used sqljdbc 4.3.0 according to the chosen answer in this link:
我根据此链接中选择的答案使用了sqljdbc 4.3.0:
com.mysql.jdbc.driver class not found exception com.mysql.jdbc.driver类未找到异常
When I did this It debugs successfully but when I run it on my device which is Samsung Galaxy Y (Gingerbread) it gives me this error: 当我这样做时,它将成功调试,但是当我在三星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.".
Any help would be highly appreciated. 任何帮助将不胜感激。
Edit: I ran it on the emulator and it gives this error in the text view. 编辑:我在模拟器上运行它,它在文本视图中给出此错误。
android.os.NetworkOnMainThreadException android.os.NetworkOnMainThreadException
You got this exception: 您遇到了以下异常:
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.
Basically, you need to do what the exception message says: 基本上,您需要按照异常消息的说明进行操作:
A couple of other things to try on your device: 在您的设备上尝试其他几件事:
Basically, there are a number of things that could be wrong, and you need to eliminate them methodically until you find the real cause of the problem. 基本上,有很多事情可能是错误的,您需要有条不紊地消除它们,直到找到问题的真正原因。 We can't do that for you.
我们不能为您做到这一点。
I ran it on the emulator and it gives this error in the text view.
我在模拟器上运行它,并在文本视图中给出了此错误。
android.os.NetworkOnMainThreadException
This is a different problem. 这是一个不同的问题。
Here's what the javadoc says: 这是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.
仅针对面向Honeycomb SDK或更高版本的应用程序抛出此错误。 Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged.
允许以较早版本的SDK为目标的应用程序在其主事件循环线程上进行联网,但不建议这样做。 See the document Designing for Responsiveness ."
请参阅文档“ 响应能力设计 ”。”
In short, you shouldn't do network stuff (including talking to off-platform databases) on the main event thread ... 'cos it is likely to cause the UI to lock up for extended periods. 简而言之,您不应该在主事件线程上进行网络工作(包括与跨平台数据库进行对话)...因为这很可能导致UI锁定较长时间。
您的网址有问题,请使用以下网址格式:
jdbc:sqlserver://server.com\\Db_name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.