1

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());
        }
}
Silvia H
  • 8,097
  • 7
  • 30
  • 33

1 Answers1

0

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.

Community
  • 1
  • 1
bytebender
  • 7,371
  • 2
  • 31
  • 54
  • 1
    First, the browser didn't ask me to login, since we adjusted it to login using windows authentication and here's our connection string: "data source=.;initial catalog=crawler;integrated security=true;" and I'll put the android code to call the web service in the question. – Silvia H Jun 04 '12 at 20:37
  • 1
    The Web Service accesses the database using the user :'NT AUTHORITY\NETWORK SERVICE.', and this user is a system admin in the sqlServer – Silvia H Jun 04 '12 at 20:45