Solved

Error Sending iCalendar events via a .Net Assembly and SQLServer

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

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.
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

23 Experts available now in Live!

Get 1:1 Help Now