我有一个安卓应用程序,我想在其中检索SqlServer 2008中的数据。
安卓应用程序连接到访问Sqlserver数据库的web服务,我尝试调用从数据库检索数据的方法"getCommentsTest“,得到以下错误:
System.Web.Services.Protocols.SoapException:服务器无法处理请求。-> System.Data.SqlClient.SqlException:无法打开登录所请求的数据库“我的数据库”。登录失败。从用户'NT AUTHORITY\NETWORK SERVICE.‘’登录失败。
知道我在发布web服务之后尝试在浏览器上查看它,我调用了这个函数,它起作用了。
下面是调用web服务的android代码:
公共空callTestGetComments() {尝试{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_GET_COMMENTS);
request.addProperty("eID", 140);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_TEST);
androidHttpTransport.call(SOAP_ACTION_GET_COMMENTS, envelope);
Object result = (Object)envelope.getResponse();
String xml=result.toString();
Document doc=XMLfromString(xml);
doc.getDocumentElement().normalize();
//System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("Comment");
//System.out.println("-----------------------");
//String commentBody,userName;
String commentBody="";
for (int i = 0; i < nList.getLength(); i++)
{
Node nNode = nList.item(i);
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;
//Comment c=new Comment();
commentBody += getTagValue("comment", eElement);
commentBody+= getTagValue("uPhone", eElement);
//System.out.println("Nick Name : " + getTagValue("nickname", eElement));
//System.out.println("Salary : " + getTagValue("salary", eElement));
//comments.add(c);
}
// tv.setText(result.toString());
tv.setText(commentBody);
}
}
catch (Exception e) {
tv.setText(e.getMessage());
}
}
发布于 2012-06-05 04:21:26
这是一个与权限相关的问题。当您在浏览器中查看web服务时,它是否要求您登录?
您使用什么方法与the服务通信?你能把代码发出来吗。我敢打赌您不会传递任何凭据,但如果不看代码,我就不能确定。
您是否有权访问SQL服务器?如果是这样,您是否检查了错误日志中的无效登录?
基于这个SO question,没有从android使用NTLM认证到windows服务的简单方法。
用户在sql服务器上是什么并不重要,因为从android设备的角度来看,他们没有经过身份验证。
https://stackoverflow.com/questions/10887418
复制相似问题