following scenario. I have a client machine on which I have all the permissions for:
- SQL-databases (db_owner)
- Full access to a Sharepoint Application.
- Created a Sql-account (db_owner) and included credentials into connection string.
I also have my developing environment on a virtual machine (VM). Here I also have any permissions possible.
My task is to write an EventReceiver which reacts when Items are added to a specific list and then writes certain data to a database. I was told by an experienced developer (who is not around anymore) that I am supposed to simulate the real world situation in my developement environment when developing. So I did the following:
- Create a 1:1 copy of the DB on the VM
- Import a list templatre created out of the actual list I have to work with (including contents)
- Write EventReceiver
- Test EventReceiver
- After I could verify that my solution is working in the VM I changed the DB-Connection strings.
- Copy xxx.wsp to client machine.
- Upload and activate the xxx.wsp
In the EventReceiver I am handling ItemAdded, ItemDeleting and ItemUpdated. The only method I was able to implement an ErrorMessage in was the ItemDeleting because the other two methods are asynchronous tasks, I guess. This is why this is the only action where I can see the error message. Well I also can tell that the ItemAdded-method does not work because no items are added to the DB.
The server has encountered the following error(s): Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
On the one hand I find this message quite selfexplonatory, but on the other hand I have db_owner permission level for the sql-database (with the very same creadentials I am logged in on the sharepoint site), which confuses me. Also I am not able to debug my solution as it was created on the VM which has Sharepoint installed contrary to my client machine.
After I got the exception I also tried following:
I tried to enclose the contents of my methods with SPSecurity.RunWithElevatedPrivileges
. This gave me an error concerning the Assembly version. Could not load type 'CodeToRunElevated' from assembly.
I am not sure but as far as I read it is supposed to be 14.0.0.0
but it was 14.900.0.0
. Not sure what this is supposed to mean.
Then I tried to install the .wsp over the SharePoint Management-Shell directly on the server. I was able to add it and to install it so Get-SPSolution gave me a list which included my .wsp marked as deployed = true. Still, now adding a ListItem did not only not add it to the database but also this time I did not even get an error message when I tried to delete this very same item from the Sharepoint list.
Please help, I am quite desparate because the EventReceiver is working on the VM so this really bugs me.