Aaabbbccc123


Hello there,

I am having trouble with the following and appreciate any help.Thanks in advanced.

I have created an assembly to delete records in exchange (which works fine when testing it in debug mode). I then create the assembly in SQL server 2005(tried both unsafe and external access btw), and then i create a stored procedure calling the assembly.

Now my error occurs when i try to execute this stored procedure in SQL Server. I get the following...

Msg 6522, Level 16, State 1, Procedure sp_DeleteExchApp, Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'sp_DeleteExchApp':
System.Security.SecurityException: System.Security.Permissions.SecurityPermission
System.Security.SecurityException:
at App_Delete.eSay.AppointmentDelete.DeleteAppointment(Guid GUID)
.

(1 row(s) affected)

Now when i have looked around the web, i have come accross people saying that it is to do with the assembly trying to access something it does not have permission for. But i cant figure out what that is or why it is throwing an error.

The code for the assembly is as follows:

Public Shared Sub DeleteAppointment(ByVal GUID As System.Guid)

Dim CalendarURL As String
Dim ItemURL As String
Dim Rs As New ADODB.Recordset
Dim Rec As New ADODB.Record
Dim Conn As New ADODB.Connection
Dim iAppt As New Appointment
Dim Target As String
Dim strCRMGUID As String
Dim strGUID As String
Dim sSQL As String
Dim Check As String

strCRMGUID = GUID.ToString

'Using the Exchange OLE DB provider
CalendarURL = "file://./backofficestorage/esay-solutions.co.uk/public folders/Office Diary"

'Open a recordset for the items in the calendar folder
Rec.Open(CalendarURL)

Rs.ActiveConnection = Rec.ActiveConnection
sSQL = "SELECT ""DAV:href"", " & _
" ""urn:schemas:calendar:location"", " & _
" ""urn:schemas:calendar:dtstart"", " & _
" ""urn:schemas:calendar:dtend"", " & _
" ""urn:schemas:httpmail:textdescription"" " & _
"from scope('shallow traversal of """ & CalendarURL & """')"

Rs.Open(sSQL, Rec.ActiveConnection, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockOptimistic, 1)
'Enumerate the recordset, checking each item's location
If Rs.RecordCount > 0 Then
Rs.MoveFirst()
Do Until Rs.EOF
'get the location of each item
Check = Rs.Fields(CdoHTTPMail.cdoTextDescription).Value
strGUID = StripGUID(Check)
'test for desired location
If (strGUID = strCRMGUID) Then
Rs.Delete()
End If
Rs.MoveNext()
Loop
End If

End Sub


Private Shared Function StripGUID(ByVal i_strAppDescription As String) As String
'Function to strip the GUID from the message field

Dim r As Integer
Dim SearchChar As String
Dim testPos As Integer
Dim GUID As String

SearchChar = "**|"

testPos = InStr(i_strAppDescription, SearchChar)
testPos = testPos + 3
If testPos > 0 Then
GUID = Mid(i_strAppDescription, testPos)
End If

StripGUID = GUID

End Function
End Class
End Namespace


Thanks again for any help.






Re: Stored procedure assembly Error

Jens K. Suessmeyer


YOu wil lhave to impersonate the user doing anything that needs permissions across SQL Server.

http://msdn2.microsoft.com/en-us/library/ms345105.aspx

Jens K. Suessmeyer

---
http://www.sqlserver2005.de
---







Re: Stored procedure assembly Error

Aaabbbccc123

Hi, thanks for the response,

I cant reference the following;
Imports Microsoft.SqlServer.Server

Where can i find this to use the windows SQL authentication





Re: Stored procedure assembly Error

Aaabbbccc123

Im using VS 2003, i think thats why i cant find it.
Any way around this




Re: Stored procedure assembly Error

Aaabbbccc123

Right,

I have upgraded to 2005, found the Microsoft.SqlServer.Server reference and done what you said. But i still get the same error message.




Re: Stored procedure assembly Error

nielsb

What does you code (T-SQL) look like that deploys (catalogs) the assembly to the database, and what does the code look like that creates the T-SQL wrapper method around your .NET method To me it seems that you have not assigned the right permision set to the assembly during deployment (however, you say in your first post that you have tried both UNSAFE as well as EXTERNAL_ACCESS). In your scenario, I'm almost sure you need to deploy with UNSAFE.

Niels