473,545 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: Windows Service creating Outllook object

Hi

I am trying to create a windows service which queries SQL
Server on timed intervals and depending on the results
send appointments to Outlook.

The problem lies when I try to create an outlook
application object.
StreamWriter sWriter6 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter6.WriteL ine(" ** Doing Outlook Stuff **");
sWriter6.Close( );

// Add it OUTLOOK
Microsoft.Offic e.Interop.Outlo ok.Application oApp = new
Microsoft.Offic e.Interop.Outlo ok.Application( );

StreamWriter sWriter10 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter10.Write Line(" ** Getting Namespace **");
sWriter10.Close ();

Microsoft.Offic e.Interop.Outlo ok.NameSpace oNS =
oApp.GetNamespa ce("mapi");

StreamWriter sWriter11 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter11.Write Line(" ** Setting Profile **");
sWriter11.Close ();
I have a try catch block around this but it never goes
into the catch block.

The log file has the following

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **
Does anyone have any ideaq why this is happening ?????
PLEASE HELP !!!!!!!!


Nov 16 '05 #1
3 2338
W Akthar,

What do you have in your try/catch block? It's hard to tell without
seeing that, but it would seem that you are not writing to the log in it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"W Akthar" <an*******@disc ussions.microso ft.com> wrote in message
news:12******** *************** *****@phx.gbl.. .
Hi

I am trying to create a windows service which queries SQL
Server on timed intervals and depending on the results
send appointments to Outlook.

The problem lies when I try to create an outlook
application object.
StreamWriter sWriter6 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter6.WriteL ine(" ** Doing Outlook Stuff **");
sWriter6.Close( );

// Add it OUTLOOK
Microsoft.Offic e.Interop.Outlo ok.Application oApp = new
Microsoft.Offic e.Interop.Outlo ok.Application( );

StreamWriter sWriter10 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter10.Write Line(" ** Getting Namespace **");
sWriter10.Close ();

Microsoft.Offic e.Interop.Outlo ok.NameSpace oNS =
oApp.GetNamespa ce("mapi");

StreamWriter sWriter11 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter11.Write Line(" ** Setting Profile **");
sWriter11.Close ();
I have a try catch block around this but it never goes
into the catch block.

The log file has the following

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **
Does anyone have any ideaq why this is happening ?????
PLEASE HELP !!!!!!!!

Nov 16 '05 #2
static void DoDataBase(Obje ct state)
{

StreamWriter sWriterss = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriterss.Write Line(" ** DO DATABASE **");
sWriterss.Close ();

SqlConnection _sqlConn;
string connString = "data source=L004
\\L004;initial catalog=NamesAn dAddresses;pers ist security
info=True;user id=sa;password= ;workstation id=L004
\\L004;packet size=4096;Max Pool Size=500";
try
{

StreamWriter sWriter1 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter1.WriteL ine(" ** Connecting
**");
sWriter1.Close( );

_sqlConn = new SqlConnection(c onnString);
_sqlConn.Open() ;

StreamWriter sWriter2 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter2.WriteL ine(" ** Connected OK
**");
sWriter2.Close( );

DataSet ds = new DataSet("Users" );

// Create a SqlDataAdapter.
SqlDataAdapter myAdapter = new
SqlDataAdapter( );

string sqlString = "SELECT [ID],
[Profile], [Password], [Subject], [Content], [Location],
[StartTime], [EndTime], [SET] FROM
[Outlook_Visit_P olling] WHERE [SET] = 0"; //FROM Names
WHERE ";
SqlCommand sqlNamesCmd = new SqlCommand
(sqlString, _sqlConn);

sqlNamesCmd.Com mandType =
CommandType.Tex t;
myAdapter.Selec tCommand = sqlNamesCmd;
myAdapter.Fill( ds);

StreamWriter sWriter3 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter3.WriteL ine(" ** Closing
Connection **");
sWriter3.Close( );

_sqlConn.Close( );

StreamWriter sWriter4 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter4.WriteL ine(" ** Closed OK
**");
sWriter4.Close( );

DataTable dsTable = ds.Tables[0];
DataRow dsRow;
for(int row=0; row < dsTable.Rows.Co unt;
row++)
{

StreamWriter sWriter5 = new
StreamWriter(@" C:\CMSOutlook.l og", true);
sWriter5.WriteL ine(" ** Count
= " + dsTable.Rows.Co unt.ToString() + " **");
sWriter5.Close( );

dsRow = dsTable.Rows[row];

string profile = "";
string password = "";
string subject = "";
string content = "";
string location = "";
int id = 0;
DateTime startTime = new DateTime
();
DateTime endTime = new DateTime();

if (!Convert.IsDBN ull(dsRow
["ID"]))
id = Int32.Parse(dsR ow
["ID"].ToString());

if (!Convert.IsDBN ull(dsRow
["Profile"]))
profile = dsRow
["Profile"].ToString().Tri mEnd();

if (!Convert.IsDBN ull(dsRow
["Password"]))
password = dsRow
["Password"].ToString().Tri mEnd();

if (!Convert.IsDBN ull(dsRow
["Subject"]))
subject = dsRow
["Subject"].ToString().Tri mEnd();

if (!Convert.IsDBN ull(dsRow
["Content"]))
content = dsRow
["Content"].ToString().Tri mEnd();

if (!Convert.IsDBN ull(dsRow
["Location"]))
location = dsRow
["Location"].ToString().Tri mEnd();

if (!Convert.IsDBN ull(dsRow
["StartTime"]))
startTime =
Convert.ToDateT ime(dsRow["StartTime"].ToString().Tri mEnd
());

if (!Convert.IsDBN ull(dsRow
["EndTime"]))
endTime =
Convert.ToDateT ime(dsRow["EndTime"].ToString().Tri mEnd());

StreamWriter sWriter6 = new
StreamWriter(@" C:\CMSOutlook.l og", true);
sWriter6.WriteL ine(" ** Doing
Outlook Stuff **");
sWriter6.Close( );

// Add it OUTLOOK

Microsoft.Offic e.Interop.Outlo ok.Application oApp
= new Microsoft.Offic e.Interop.Outlo ok.Application( );

StreamWriter sWriter10 = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter10.Write Line(" ** Getting Namespace
**");
sWriter10.Close ();
Microsoft.Offic e.Interop.Outlo ok.NameSpace oNS =
oApp.GetNamespa ce("mapi");

StreamWriter sWriter11 = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter11.Write Line(" ** Setting Profile **");
sWriter11.Close ();

if (password == "")
oNS.Logon(profi le, Missing.Value, false,
true);
else
oNS.Logon(profi le, password, false, true);

StreamWriter sWriter12 = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter12.Write Line(" ** Getting Appointment
**");
sWriter12.Close ();

Microsoft.Offic e.Interop.Outlo ok.AppointmentI tem
oAppt = (Microsoft.Offi ce.Interop.Outl ook.Appointment Item)
oApp.CreateItem
(Microsoft.Offi ce.Interop.Outl ook.OlItemType. olAppointment
Item);
oAppt.Subject = subject;
oAppt.Body = content;
oAppt.Location = location;
oAppt.Start = startTime;
oAppt.End = endTime;

oAppt.ReminderS et = true;

oAppt.ReminderM inutesBeforeSta rt = 5;
oAppt.BusyStatu s =
Microsoft.Offic e.Interop.Outlo ok.OlBusyStatus .olBusy ; //
olBusy

oAppt.IsOnlineM eeting = false;

StreamWriter sWriter13 = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter13.Write Line(" ** Saving Appointment
**");
sWriter13.Close ();

oAppt.Save();

StreamWriter sWriter14 = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter14.Write Line(" ** Logging off **");
sWriter14.Close ();

oNS.Logoff();

oApp = null;
oNS = null;
oAppt = null;

StreamWriter sWriter7 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter7.WriteL ine(" ** Finished Outlook
Stuff **");
sWriter7.Close( );
StreamWriter sWriter8 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter8.WriteL ine(" ** Update Database **");
sWriter8.Close( );

// everything ok so update Database
UpdateDatabase( id);

StreamWriter sWriter9 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter9.WriteL ine(" ** Finished Update
Database **");
sWriter9.Close( );
// Add it to a log file
StreamWriter sWriter = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter.WriteLi ne("Profile : " +
profile);
sWriter.WriteLi ne("Subject : " +
subject);
sWriter.WriteLi ne("Content : " +
content);
sWriter.WriteLi ne("Location : " +
location);
sWriter.WriteLi ne("StartTime : " +
startTime.ToStr ing());
sWriter.WriteLi ne("EndTime : " +
endTime.ToStrin g());

sWriter.Close() ;
}
}
catch(Exception e)
{
// Add it to a log file
StreamWriter sWriter = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter.WriteLi ne("----------------------------");
sWriter.WriteLi ne("----------------------------");
sWriter.WriteLi ne(e.Message.To String());
sWriter.WriteLi ne("----------------------------");
sWriter.WriteLi ne("----------------------------");

sWriter.Close() ;
}
}

static void UpdateDatabase( int id)
{

try
{
SqlConnection sqlConn;
string connString = "data source=L004\\L0 04;initial
catalog=NamesAn dAddresses;pers ist security info=True;user
id=sa;password= ;workstation id=L004\\L004;p acket
size=4096;Max Pool Size=500";

sqlConn = new SqlConnection(c onnString);
sqlConn.Open();

DataSet ds = new DataSet("Users" );

// Create a SqlDataAdapter.
SqlDataAdapter myAdapter = new SqlDataAdapter( );

string sqlString = "UPDATE [Outlook_Visit_P olling] SET
[SET] = 1 WHERE [ID] = @ID"; //FROM Names WHERE ";

SqlCommand cmCommand = new SqlCommand(sqlS tring, sqlConn);
cmCommand.Comma ndType = CommandType.Tex t;
cmCommand.Param eters.Add(new SqlParameter("@ ID", id));
cmCommand.Execu teNonQuery();

sqlConn.Close() ;
}
catch(Exception e)
{
// Add it to a log file
StreamWriter sWriter = new StreamWriter
(@"C:\CMSOutloo k.log", true);

sWriter.WriteLi ne("----------------------------");
sWriter.WriteLi ne("----------------------------");
sWriter.WriteLi ne(e.Message.To String());
sWriter.WriteLi ne("----------------------------");
sWriter.WriteLi ne("----------------------------");

sWriter.Close() ;
}
}
Nov 16 '05 #3
The problem is that "Outlook" (or any other Office application) is not
built to be automated from "Windows Services".
Don't know which identity is used to run your service, but try with
"LocalSyste m" and set "Interact with Desktop" and watch the nice dialog box
wich remains invisible when you run under another identity.

Willy.

"W Akthar" <an*******@disc ussions.microso ft.com> wrote in message
news:12******** *************** *****@phx.gbl.. .
Hi

I am trying to create a windows service which queries SQL
Server on timed intervals and depending on the results
send appointments to Outlook.

The problem lies when I try to create an outlook
application object.
StreamWriter sWriter6 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter6.WriteL ine(" ** Doing Outlook Stuff **");
sWriter6.Close( );

// Add it OUTLOOK
Microsoft.Offic e.Interop.Outlo ok.Application oApp = new
Microsoft.Offic e.Interop.Outlo ok.Application( );

StreamWriter sWriter10 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter10.Write Line(" ** Getting Namespace **");
sWriter10.Close ();

Microsoft.Offic e.Interop.Outlo ok.NameSpace oNS =
oApp.GetNamespa ce("mapi");

StreamWriter sWriter11 = new StreamWriter
(@"C:\CMSOutloo k.log", true);
sWriter11.Write Line(" ** Setting Profile **");
sWriter11.Close ();
I have a try catch block around this but it never goes
into the catch block.

The log file has the following

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **

** DO DATABASE **
** Connecting **
** Connected OK **
** Closing Connection **
** Closed OK **
** Count = 5 **
** Doing Outlook Stuff **
Does anyone have any ideaq why this is happening ?????
PLEASE HELP !!!!!!!!

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
361
by: MrFez | last post by:
I have a simple .Net console program that sends an email message. The message can be specified as a string or a filename on the command line. Refer to the code below. The problem I am having is that it works fine on one computer (my workstation) for messages of any size but it fails on another computer (my test server) for messages larger...
7
712
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: service 1 - my service watches service 2 - windows service service 2 is stopped - service 1 starts service 2
6
3790
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop() ServiceController.WaitForStatus(ServiceControllerStatus.Stopped) ServiceController.start() but doesn´t works. It seems waitforstatus instruction is the last
2
11796
by: Val3 | last post by:
Hi all. I need to build dll(s) and windows services using VB .NET 2005 Express. When I make File/New project the windows contain only Windows application, Windows control library, Console application, DVD collection starter kit. How can I do? Any suggest? Thanks in advance. VAL
6
1899
by: Picho | last post by:
Hi all. I have a webservice and a windows app. both of them reference the same class library called WebServiceTest.Core that defines a class called Class1. the webservice exposes a method that looks like this: public WebServiceTest.Core.Class1 GetClass1()
4
7922
by: Johny_W | last post by:
hi guys, I have encountered a problem with IE automation (.NET 2.0, C#, mshtml, SHDocVw). I am writing a class for manipulating specific html pages with frames. It is supposed to be used from a web service. The problem is that when I use the InternetExplorer object in web service, it seems like the underlying IE doesn't support frames. ...
8
4365
by: Blaine Manyluk | last post by:
Greetings... I have some strange problems involving: Access 2000 (9.0.4402 SR-1) Windows 2000 Server 5.00.2195 Service Pack 4 Access apps with Oracle/ODBC back ends One app is a reporting one, and it opens reports (in either View or Print mode) from a master form. The code opens the
7
2071
by: Giulio Petrucci | last post by:
Hi everybody, I've a big problem with a Windows Service I've created using C#. It's a very simple service: it just starts a TcpListener listening for incoming connections on a certain ports. First I compiled it on FW2.0, and run the service without any problem. Some days ago I had to performe a sort of "backporting" to FW1.1, I compiled the...
7
2274
by: Diego F. | last post by:
Hello. I have a windows service running that listens to a port and makes insert queries in a database. I need to make an interface, so my idea is creating a simple windows application that just shows messages from the service. Can I do that with remoting? What are the main steps to do that? --
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.