title: How to connect android application to MSSQL server and retrive data from it?
body: <p>I am trying to connect my app to Microsoft SQL server 2008 R2 and retrieve data from it. I can connect my app to MySql through out php but can't complete the same task in terms of MSSQL server. I have googled <a href="http://amitku.wordpress.com/2011/08/03/how-to-connect-and-access-sql-database-server-from-android-app/" rel="nofollow noreferrer">this</a>
  and <a href="https://stackoverflow.com/questions/25461125/android-application-not-connecting-to-mssql-server-2008">this</a>
  links. But these links don't tell me exactly the procedure that I should follow. Here in <a href="http://www.basic4ppc.com/android/forum/threads/connect-android-to-ms-sql-server-tutorial.13166/" rel="nofollow noreferrer">this</a>
  link I found something that tells me to work with asp. But I can't cope the code. As a new one to do so, can anyone please tell me step by step procedure about connecting android app to MSSQL server? Need the solution pretty badly.
  On the other hand, some of the comments and answer tells me that I should use web service. How should I implement web service in my code. I can retrieve data from MySql source through json parsing via PHP code. Should I use, ASP instead of PHP. Then how should I do it?
  What I have done as a novice is as below.</p>
  <p>Tried out connecting the server directly.</p>
  <pre><code>public void query()
  {
          Log.e(&quot;Android&quot;,&quot; SQL Connect Example.&quot;);
          Connection conn = null;
          try {
              String driver = &quot;net.sourceforge.jtds.jdbc.Driver&quot;;
              Class.forName(driver).newInstance();
              //test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
              String connString = &quot;jdbc:jtds:sqlserver://192.168.115.16:1433/WSMS_H;user=sa;password=123456;integratedSecurity=true;&quot;;
              String username = &quot;&quot;;
              String password = &quot;&quot;;
              conn = DriverManager.getConnection(connString,username,password);
              Log.e(&quot;Connection&quot;,&quot;open&quot;);
              Statement stmt = conn.createStatement();
              ResultSet reset = stmt.executeQuery(&quot;select * from dbo.Users&quot;);
               
              //Print the data to the console
              while(reset.next()){
              Log.e(&quot;Data:&quot;,reset.getString(3));
          //                Log.w(&quot;Data&quot;,reset.getString(2));
              }
              conn.close();
               
          }
          catch (Exception e)
          {
              Log.w(&quot;Error connection&quot;,&quot;&quot; + e.getMessage());
          }
      }
  </code></pre>
  <p>Which is not a proper way I confess. What I have is a MS SQL server 2008 R2 installed in my local machine. 1433 port working for SQL server. But the connection string returns null.</p>
  <p>Can somebody show me what should I do to complete the connection?Thanks for any kind of help.</p>