Prev: Deployment Package checking to see if file exists
Next: How can I set the character that a TextBox may Interpret as NewLin
From: win on 18 Jan 2010 06:16 Send mail on event Outlook.Application outLookApp = new Outlook.ApplicationClass(); outLookApp.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler (Application_SendItem); But if I write the event into a file, all ok. void Application_SendItem(object Item, ref bool Cancel) { MessageBox.Show("Send Item"); StreamWriter writer = new StreamWriter("C:\\Log.txt"); writer.WriteLine("Send Item"); writer.Close(); } If I connect with mysql db. Event is raised only the first time! void Application_SendItem(object Item, ref bool Cancel) { MySqlConnection myConn; myConn = new MySqlConnection ("Server=localhost;Database=db;Uid=uid;Pwd=pw;"); myConn.Open(); myConn.Close(); } After my program does not detect events outlook! You know why? Windows Xp Mysql : 5 Microsoft Outlook 2003 C# Thanks!
From: Jesse Houwing on 19 Jan 2010 18:17
* win wrote, On 18-1-2010 12:16: > Send mail on event > > Outlook.Application outLookApp = new Outlook.ApplicationClass(); > outLookApp.ItemSend += new > Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler > (Application_SendItem); > > But if I write the event into a file, all ok. > > void Application_SendItem(object Item, ref bool Cancel) > { > MessageBox.Show("Send Item"); > StreamWriter writer = new StreamWriter("C:\\Log.txt"); > writer.WriteLine("Send Item"); > writer.Close(); > } > > If I connect with mysql db. Event is raised only the first time! > > void Application_SendItem(object Item, ref bool Cancel) > { > MySqlConnection myConn; > myConn = new MySqlConnection > ("Server=localhost;Database=db;Uid=uid;Pwd=pw;"); > myConn.Open(); > myConn.Close(); > } > After my program does not detect events outlook! > > You know why? > > Windows Xp > Mysql : 5 > Microsoft Outlook 2003 > C# > > > Thanks! I'm not sure why, but your current code for connecting to MySQL has a few serious problems in the form of possible resource leaks. I'm not sure if they are the actual cause of your problem, but you might want to solve these first: Make sure you properly dispose resources you create to access the database: using (MySqlConnection myConn = new MySqlConnection ("Server=localhost;Database=db;Uid=uid;Pwd=pw;")) { myConn.Open(); ... Access database here } .... No need to call close, the using statement will take care of that. Any MySqlCommand, DataAdapter, Dataset, datareader etc needs to be properly closed as well. Leaving open connections or such objects can cause very strange behavior. when you use a using statement, the resources will be properly closed, even in case of exceptions. -- Jesse Houwing jesse.houwing at sogeti.nl |