title: WCF Service Security Exception caused when trying to access data via LINQ to SQL
body: <p>I'm currently in the beginning of learning WCF, as some of the concepts and the functionality they provide look interesting and also useful in a project I'm undertaking.</p>
  
  <p>So far I've been following some pretty simple guides to get the hang of it but after creating my first host service I've come a bit unstuck, after trying to retrieve some data from a SQL Database and recieving the following error while using LINQ to SQL:</p>
  
  <pre><code>Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
  </code></pre>
  
  <p>I've had a look around and seen some suggestions as how to fix this, but non have seemed to be applicable as I'm creating a simple WCF service library purely for testing.</p>
  
  <p>The code trips up on the following line:</p>
  
  <pre><code>me = aDb.Messages.ToList();
  </code></pre>
  
  <p>The project itself is held on a remote drive, but when I run to debug is run locally, however the database is a test server located again remotely. All the SQL credentials are correct as the connection tests succesfully and I've checked the connection string. Finally the service is running as a basicHttp Below you can see all my code so if you have any ideas as to how I can stop the error it would be appreciated.</p>
  
  <pre><code>namespace AnnouncementServiceLibrary
  {
      [ServiceContract]
      public interface IConnect
      {
          [OperationContract]
          List&lt;Mess&gt; ConnectUser(string userId);
      }
  }
  
  namespace AnnouncementServiceLibrary
  {
      public class AnnounceService : IAnnounceService
      {
  #region IConnect Members
  
          public List&lt;Mess&gt; ConnectUser(string userId)
          {
                  List&lt;Mess&gt; mess = new List&lt;Mess&gt;();
                  List&lt;Message&gt; me;
                  List&lt;MessageLink&gt; messLink;
  
                  AnnouncementDBDataContext aDb = new AnnouncementDBDataContext();
  
                  me = aDb.Messages.ToList();
                  messLink = aDb.MessageLinks.ToList();
  
                  var result = (from a in messLink
                                join b in me
                                    on a.UniqueID equals b.UniqueID
                                where a.UserID == userId
                                select new { b.UniqueID, b.Author, b.Title, b.Body, b.Priority, a.Read, b.TimeRecieved }).
                      DefaultIfEmpty();
  
                  foreach (var a in result)
                  {
                      mess.Add(new Mess(a.UniqueID, a.Author, a.Title, a.Body, a.Priority, (bool)a.Read, a.TimeRecieved));
                  }
                  return mess;
          }
          #endregion
      }
  }
  </code></pre>