Hello,
I have a SharePoint Custom List and I’m going to update a database (none-SharePoint DB, located in different server) while my Custom List is changed (for example by adding new item).
I created a sandboxed solution and an event receiver for ItemAdding and used linq for inserting new Item to a table called FromSharePoint:
 public override void ItemAdding(SPItemEventProperties properties)
      {
           String connectionString = “Data Source=172.16.0.15;Initial Catalog=test;Persist Security Info=True;User ID=sara;Password=123”;
          base.ItemAdding(properties);
          FromSharePoint fromSharePoint = new FromSharePoint();
          TestDataContext dc = new TestDataContext(connectionString);
          try
          {
              fromSharePoint.ItemID = Convert.ToInt32(properties.ListItem[“ID”]);
              fromSharePoint.Title = properties.ListItem[“Title”].ToString();
              dc.FromSharePoints.InsertOnSubmit(fromSharePoint);
              dc.SubmitChanges();
          }
          catch (Exception ex)
          {
              dc.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
              dc.SubmitChanges();
          }
          finally
          {
              dc.Dispose();
          }
      }
However, by adding new item to the list I get the following error:
Request for the permission of type ‘System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.
I tried following solutions but my problem is still remained:
- changing wss_mediumtrust.config and wss_minimaltrust.config like what mentioned in this post didn’t work
- Setting trust level to Full in web.config didn’t work
I also tested my problem in a farm solution, interestingly I didn’t receive the above error but my database didn’t change.
Does anyone have an idea??
Can you please try to provide the database owner permission for system account (service account) on non-SharePoint database and test it again.