title: Webservice to SQL server phonegap app
body: <p>I'm creating a Phonegap application that needs to connect to an SQL database and return the data to the application.</p>
  
  <p>How can i set up a WebMethod that will:</p>
  
  <ol>
  <li>Create a connection to the database</li>
  <li>Query the database for any records</li>
  <li>Return found records to the mobile app </li>
  </ol>
  
  <p>I'm using Phonegap Build so i cannot really use any plugins and the Webservice and SQL database are hosted on my computer, so I will be connecting to them through 192.168.xxx.xxx.</p>
  
  <p>EDIT:
  So far i have a this calling to the web service from the Javascript:  </p>
  
  <p>index.js::</p>
  
  <pre><code>var url = "http://192.168.xxx.xxx:1234/"
  $.ajax({
          type: "POST",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          url: url + "WebService.asmx/HelloWorld",
          data: "{}",
          success: function (data) {
          $("#ul_DeviceList").append('&lt;li&gt;Example ' + data.d + '&lt;/li&gt;').listview('refresh');
          },
          error: function (data) {
          alert(data.status + " : " + data.statusText);
          }
  });
  </code></pre>
  
  <p>WebService.cs::</p>
  
  <pre><code>[System.Web.Script.Services.ScriptService]
  public class WebService : System.Web.Services.WebService
  {
      [WebMethod]
      public string HelloWorld()
      {
          return "Hello World";
      }
  </code></pre>
  
  <p>This is so i can tell if the device has connected to the Server, which it does.</p>
  
  <p>Now i believe need to do something along the lines of :</p>
  
  <pre><code>    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
          [WebMethod]
          public void GetData()
          {
              SqlCeConnection conn = new SqlCeConnection(*Connection string will go here*);
              conn.Open();
             ..etc etc...
  </code></pre>
  
  <p>But at the moment i cannot seem to add System.data.SqlServerCe to my project..</p>