Solved

Error Sending iCalendar events via a .Net Assembly and SQLServer

Posted on 2013-05-14
2
340 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql 2014,  lock limit 5 32
SQL Server 2012 r2 - Sum totals 2 25
Help Required 3 97
Need help how to find where my error is in UFD 6 30
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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