?
Solved

Error Sending iCalendar events via a .Net Assembly and SQLServer

Posted on 2013-05-14
2
Medium Priority
?
390 Views
Last Modified: 2013-05-17
I've been trying to find a way to add an event to an Outlook calendar using data in a database table.
To that end, I've been trying to implement this solution which looks like it covers what I need, but I've gotten stuck at a point before I can test it properly.

So far I've created a class called iCalEmail, registered the build as an assembly with SQL Server, and created a procedure to call that assembly.
Unfortunately it was all going a little too well - my build returns the following error when I run the procedure:

System.ArgumentException: Item has already been added. Key in dictionary: 'method'  Key being added: 'method'
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at System.Collections.Specialized.StringDictionary.Add(String key, String value)
   at System.Net.TrackingStringDictionary.Add(String key, String value)
   at iCalEmail.StoredProcedures.SendiCal(DateTime startDateTime, DateTime endDateTime, String emailSubject, String userName, String userEmailAddress, String cnAttendee, String methodType, DateTime createdOn, String notes, String UID, String location, String seqNo, String smtpserver, Int32 smtpport)

I searched around online and saw that a lot of people seem to be suggesting that I'm either using a collection which has duplicate keys, or that I have two environment variables with the same name. I could be missing something, but so far as I can tell neither of these solutions apply.

Can anyone discern what could be causing the exception?


Class and Procedure to follow:


CREATE ASSEMBLY [iCalEmail]
AUTHORIZATION [dbo]
FROM 'C:\iCal\iCalEmail.dll'
WITH PERMISSION_SET = UNSAFE

Open in new window


create procedure dbo.usp_mb_eventnotify(@startDateTime datetime
	, @endDateTime datetime
	, @emailSubject nvarchar(255)
	, @userName nvarchar(255)
	, @userEmailAddress nvarchar(255)
	, @cnAttendee nvarchar(255)
	, @methodType nvarchar(255)
	, @createdOn datetime
	, @notes nvarchar(255)
	, @UID nvarchar(255)
	, @location nvarchar(255)
	, @seqNo nvarchar(255)
	, @smtpserver nvarchar(255)
	, @smtpport int)
as external name iCalEmail.[iCalEmail.StoredProcedures].SendiCal;

Open in new window


exec CreateEvent '2013-05-14 11:00:00'
	, 'Test Appointment'
	, 'Paul Atherton'
	, 'paul.atherton@email.co.uk'
	, 'This is a test appointment'
	, 'Testing Location - The test base'

Open in new window

StoredProcedures.cs
0
Comment
Question by:CaptainGiblets
  • 2
2 Comments
 
LVL 6

Author Comment

by:CaptainGiblets
ID: 39167314
Ah, I missed something out.

The StoredProcedure CreateEvent calls dbo.usp_mb_eventnotify (as seen above) and passes some default parameters -

CREATE PROCEDURE [dbo].[CreateEvent] 
	-- Add the parameters for the stored procedure here
	@eventDateTime datetime
	, @eventTitle nvarchar(255)
	, @userName nvarchar(255)
	, @userEmailAddress nvarchar(255)
	, @eventDescription nvarchar(255)
	, @eventLocation nvarchar(255)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @Now datetime;

	SET @Now = GETDATE();

    -- Insert statements for procedure here
	exec dbo.usp_mb_eventnotify @eventDateTime
	, @eventDateTime
	, @eventTitle
	, @userName
	, @userEmailAddress
	, @userEmailAddress
	, 'REQUEST'
	, @Now
	, @eventDescription
	, ''
	, @eventLocation
	, '1'
	, 'mail.local'
	, '25'
END

Open in new window



I'm posting this for completions sake, as the issue seems to be with the class file.

I'll keep looking around and tweaking it in the meantime.
0
 
LVL 6

Accepted Solution

by:
CaptainGiblets earned 0 total points
ID: 39174042
Was busy with some stuff but finally got back around to it, and apparently the little break was all I needed because I spotted the problem almost immediately x_x

var calendarType = new System.Net.Mime.ContentType("text/calendar;method=REQUEST; charset=UTF-8");
calendarType.Parameters.Add("method", "REQUEST");

Open in new window


Just as the error message specified, the "method" property was being added to a collection where it already existed. I simply removed the ..Parameters.Add(..); line and everything worked fine.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question