Solved

Error Sending iCalendar events via a .Net Assembly and SQLServer

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now