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??
Dear Muhammed,
I use SharePoint 2010 and VS 2010. But I keep RER in mined if we upgrade to 2013.
Thanks.
Dear Hemnat,
Thanks for you reply.
I set owner permission for system account but it didn’t solve my problem. However, I could address it by creating a new farm solution.
Eventually, I solved the problem
I created a farm solution instead of sandboxed and used properties.AfterProperties for getting required fields.
The problem in sandboxed solution still remains unsolved. But not important, because farm solution is OK for me.
Setting owner permission for system account didn’t work.
Hi ,
If you are using sharepoint 2013 and app model i recommend for you to use RER (remote event reciver) it will be more powerful and good for your case specifically when you are going to interact with multiple external database instance …
Thanks,
ME.
Can you please try to provide the database owner permission for system account (service account) on non-SharePoint database and test it again.