Solved

Error Sending iCalendar events via a .Net Assembly and SQLServer

Posted on 2013-05-14
2
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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