'System.Web.Services.Protocols.SoapException: Server was unable to process request.---> System.Data.SqlClient.SqlException:

I have an android application in which i want to retrieve data from SqlServer 2008.

The android application connects to a web service that accesses the Sqlserver database, I tried calling the method "getCommentsTest" that retrieves data from the database and I got this error:

System.Web.Services.Protocols.SoapException: Server was unable to process request.---> System.Data.SqlClient.SqlException: Cannot open database "my database" requested by the login. The login failed. Login failed from user 'NT AUTHORITY\NETWORK SERVICE.'

Knowing that I tried to view the web service on the browser after publishing it, I called the function and it worked.

And here's the android code to call the web Service:

public void callTestGetComments() { try {

        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());
        }
}


Solution 1:[1]

This is a permissions related issue. When you view the web service in the browser did it ask you to login?

What method are you using to talk to the webservice? Can you post that code. I would be willing to bet you are not passing any credentials but I can't be certain without seeing the code.

Do you have access to the SQL server? If so have you checked the error logs for invalid logins?

Based on this SO question there is no easy way to authenticate to a windows service using NTLM from an android.

It doesn't matter what they user is on the sql server because from the standpoint of the android device they are not authenticated.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community