title: How to have silverlight get its data from MySQL
body: <p>I've written a small hello world test app in Silverlight which i want to host on a Linux/Apache2 server. I want the data to come from MySQL (or some other linux compatible db) so that I can databind to things in the db.</p>
  
  <p>I've managed to get it working by using the <a href="http://www.mysql.com/products/connector/net/" rel="nofollow noreferrer">MySQL Connector/.NET</a>:</p>
  
  <pre><code>MySqlConnection conn = new MySqlConnection("Server=the.server.com;Database=theDb;User=myUser;Password=myPassword;");
  conn.Open();
  MySqlCommand command = new MySqlCommand("SELECT * FROM test;", conn);
  using (MySqlDataReader reader = command.ExecuteReader())
  {
       StringBuilder sb = new StringBuilder();
       while (reader.Read())
       {
           sb.AppendLine(reader.GetString("myColumn"));
       }
       this.txtResults.Text = sb.ToString();
  }
  </code></pre>
  
  <p>This works fine if I give the published ClickOnce app full trust (or at least SocketPermission) and <strong>run it locally</strong>. </p>
  
  <p>I want this to run on the server and I can't get it to work, always ending up with permission exception (SocketPermission is not allowed).</p>
  
  <p>The database is hosted on the same server as the silverlight app if that makes any difference.</p>
  
  <p><strong>EDIT</strong>
  Ok, I now understand why it's a bad idea to have db credentials in the client app (obviously). How do people do this then? How do you secure the proxy web service so that it relays data to and from the client/db in a secure way? Are there any examples out there on the web?</p>
  
  <p>Surely, I cannot be the first person who'd like to use a database to power a silverlight application?</p>