|
H! All
I have a problem starting window service..i made some adjustment in this existing window service program..i changed the connection string to connect to Oracle(from app.config)..I also added the Oracle Data.Access in the references..and also installed ODT with ODAC 11.1.0.621 driver Oracle.Data.AccessClient in references). From OnStart, it calls a function LLProcess, from there it connects to a web service to execute another function that gets data from SQL Server 2005 and then return it as xml data..and then process this data to save in the oracle database..I tested the program and it was running fine..It can get xml data and saves it to Oracle database. I rebuilt the existing installer and installed it, but when i tried to start it from services, an error pops up..("error 1053: The service did not respond to the start or control request in a timely fashion"). The program uses System.Threading..
I don't know where the error came from..is it the Oracle references might causes the problem? DLL's?
Another thing is that i can execute(or double click) the EXE file manually after the installation and it was running successfully. If that is the case, is it normal for a window service EXE to be run manually?
BTW, The existing program was previously connecting to AS400 and was running in our production server already..
Anyone please help! Thanks!
Regards
|
|
|
|
|
May be some references are missing....
Also,try to catch the error and write into log file.So that exact error can be found
himanshu
|
|
|
|
|
thanks for the reply...
i already tried to write to a log file..when i started the service, it passes the process..but did not passed thru error handler(catch)..it just loop and loop in the function..and i think when it reaches 100+ loops(that's when the progress bar in the service reaches its half value), the error pops up..
What are the possible references that i missed?
Thanks and regards
|
|
|
|
|
Hi
I have two points to ask
(1)obrix_activex wrote: it passes the process..but did not passed thru error handler(catch)..it just loop and loop in the function
In which function this loop is going on?
(2)You have written try catch block in OnStart only?
himanshu
|
|
|
|
|
Nope..I have a function called LLPlusProcess...
This some content of OnStart..
intervalEnqueue = 600;
timer1 = new Timer(new TimerCallback(LLPlusProcess), null, intervalEnqueue, intervalEnqueue);
then inside the LLPlusProcess function it loops..waiting for some data to retrieve from SQL server..
Problem is that after how many loops an error pops up(this error pops up when i start the window service in the services.msc...
|
|
|
|
|
Have you write try catch block in LLPlusProcess function.
your best bet to solve this is try to write key steps in log file like
When you call LLPlusProcess function,Inside LLPlusProcess function and when LLPlusProcess function ends.Just try to find upto which point your code is executed by reading log file.
himanshu
|
|
|
|
|
Check the connection string. Is that correct?
|
|
|
|
|
I think so because during debug mode..i can connect to oracle (save and retrieve the data)... the only problem is that when i installed it and tried to start it in the services.msc..it has an error mentioned in my previous message..
|
|
|
|
|
How many times are you going to ask this?
What does your OnStart method lok like now?
|
|
|
|
|
ok..this is the whole code in service1.cs..error or time out comes inside the function LLPlusProcess for how many loops..i dont know if it uses too many thread..please help..tnx!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
//using System.Timers;
using System.Threading;
using System.Net.NetworkInformation;
using System.IO;
namespace LLPlus
{
public partial class Service1 : ServiceBase
{
Timer timer1;// enqueue
Service service;// = new Service();
string refIDEQ = null;
bool enqued = false;
string strconn;
OracleConnection conn;
OracleCommand cmd;
public Service1()
{
InitializeComponent();
}
public void InitializeConnection()
{
strconn = System.Configuration.ConfigurationManager.ConnectionStrings ["OracleConnection"].ToString();
conn = new OracleConnection(strconn);
cmd = new OracleCommand();
}
public void Start()
{
int intervalEnqueue;
try
{
InitializeConnection();
if (Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["enqueueDelay"]) > 0)
{
intervalEnqueue = Int32.Parse (System.Configuration.ConfigurationManager.AppSettings["enqueueDelay"]) * 1000;
timer1 = new Timer(new TimerCallback(LLPlusProcess), null, intervalEnqueue, intervalEnqueue);
}
else
{
AddToFile("Start...");
intervalEnqueue = 600;
timer1 = new Timer(new TimerCallback(LLPlusProcess), null, intervalEnqueue, intervalEnqueue);
}
}
catch (Exception e)
{
System.Diagnostics.Debug.Write("\r\n[Start] Error: " + e.Message);
}
}
protected override void OnStart(string[] args)
{
Start();
}
protected override void OnStop()
{
timer1.Dispose();
conn.Close();
}
public void LLPlusProcess(object state)
{
System.Diagnostics.Debug.Write(" LLPlus [ENQUEUE] : Service Started at " + DateTime.Now.ToString() + " \r\n");
if (!enqued)
{
try
{
enqued = true;
GetSMSResult getIncomingSMSResult = new GetSMSResult();
getIncomingSMSResult = null;
service = new Service();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
getIncomingSMSResult = service.GetSMS(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], System.Configuration.ConfigurationManager.AppSettings["enqueueStatus"], "Waiting", Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["enqueueRecord"]));
string getIncomingSMSResultResponse = getIncomingSMSResult.ResponseMessage;
System.Diagnostics.Debug.Write(getIncomingSMSResultResponse + "\r\n");
GetSMSResultMessage[] getIncomingSMSResultMessage = null;
getIncomingSMSResultMessage = getIncomingSMSResult.Message;
if (getIncomingSMSResultMessage != null)
{
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage.Length + "\r\n");
for (int x = 0; x < getIncomingSMSResultMessage.Length; x++)
{
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].DateReceived + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].Keyword + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].MessageText + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].ReferenceID + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].Sender + "\r\n");
System.Diagnostics.Debug.Write("COUNTER " + x + "\r\n");
try
{
refIDEQ = getIncomingSMSResultMessage[x].ReferenceID;
string sql = "INSERT INTO PLP_ENQUE_DEQUE(ref_id,service_no,keyword,msg_in,status) "
+ " VALUES ('" + getIncomingSMSResultMessage[x].ReferenceID + "','" +
getIncomingSMSResultMessage[x].Sender + "','" +
getIncomingSMSResultMessage[x].Keyword + "','" +
getIncomingSMSResultMessage[x].MessageText + "','E')";
conn.Open();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
int recAffected = cmd.ExecuteNonQuery();
conn.Close();
if (recAffected > 0)
{
string updateSMS = service.UpdateSMSStatus(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], getIncomingSMSResultMessage[x].ReferenceID, System.Configuration.ConfigurationManager.AppSettings["enqueueSuccessMsg"]);
System.Diagnostics.Debug.Write(" UPDATE SMS : " + updateSMS + "\r\n");
}
else
{
string updateSMS = service.UpdateSMSStatus(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], getIncomingSMSResultMessage[x].ReferenceID, System.Configuration.ConfigurationManager.AppSettings["enqueueFailedMsg"]);
System.Diagnostics.Debug.Write(" UPDATE SMS : " + updateSMS + "\r\n");
}
}
catch (Exception icmsEx)
{
System.Diagnostics.Debug.Write("ENQUEUE [EX] 2: " + icmsEx.ToString());
if (icmsEx.Message.ToLower().StartsWith("unspecified error"))
{
InitializeConnection();
}
else
{
string updateSMS = service.UpdateSMSStatus(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], getIncomingSMSResultMessage[x].ReferenceID, icmsEx.Message);
System.Diagnostics.Debug.Write("ENQUEUE [ICMSEX] " + icmsEx.ToString());
}
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write("ENQUEUE [EX] : " + ex.ToString());
}
System.Threading.Thread.Sleep(100);
enqued = false;
}
else
{
System.Diagnostics.Debug.Write("\r\n ---- ENQUEUE PROCESS ON GOING ----\r\n ");
}
}
}
}
|
|
|
|
|
For my Windows Services, I set the database connections in the constructor.
Ideally your OnStart and OnStop methods would only be:
public void OnStart()
{
timer1.Start() ;
}
public void OnStop()
{
timer1.Stop() ;
}
I add some logging as well, but the point is that you want to be doing very little in these methods; it's not the place to be setting up a database connection.
0) Set up the connection in the constructor
1) Start the timer in OnStart
2) Stop the timer in OnStop
3) In the timer callback method (LLPlusProcess?): open the connection, use it, and close it.
After further reading of your code, I think you may have bigger problems, but start with that and see how it goes.
|
|
|
|
|
I have a pretty simple FileSystemWatcher setup as follow:
var sw = new FileSystemWatcher();<br />
sw.Path = dir;<br />
sw.Filter = "*";<br />
sw.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;<br />
sw.Changed += new FileSystemEventHandler(OnChanged);<br />
sw.Created += new FileSystemEventHandler(OnChanged);<br />
sw.Deleted += new FileSystemEventHandler(OnChanged);<br />
sw.Renamed += new RenamedEventHandler(OnRenamed);<br />
sw.EnableRaisingEvents = true;<br />
The unfortunate thing is, when I open a file with Notepad, edit it and save, I got 2 Changed event.
How come? what should I do to get only 1 event?
Any ideas or link!?
PS: I'm running Vista Ultimate x64
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I used a stupid hack.
I made a table of last access.
If it's less than 1s ago, I do nothing...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi,
FileSystemWatcher is not perfect; it typically fires multiple times when something happens to a file, often because one user action causes several technical operations on the directory entry: a file gets created/opened, data gets written, when the file gets flushed or closed some metadata gets updated, etc.
AFAIK there is nothing you can do against that, if you only want one event, you have to take whatever number of events coming at you and filter them yourself.
And the most useful feature is missing, it would fire an event (just one!) when one is done acting on a file, the way it operates right now is it fires from the beginning of an action, so one never is sure the file isn't in some intermediate state.
BTW: FileSystemWatcher also may drop some events, e.g. when there is much activitity going on in your watched folder.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Good to know!
Anyway I am watching human edited config file, so I should be ok!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
HI Experts
I m inserting image in DB.I have made connection object and passed con. string in it....when my control comes to Executnonquery it gives me error as ->
ExecuteNonQuery: Connection property has not been initialized.
I m not getting the solution to it....
|
|
|
|
|
send the code plzzzzzzz
|
|
|
|
|
The Code Is
this.sqlConnection1.Open();
if (sqlCommand1.Parameters.Count == 0)
{
this.sqlCommand1.CommandText = "INSERT INTO tblImgData(ID," +
" Name,Picture) values(@ID,@Name,@Picture)";
this.sqlCommand1.Parameters.Add("@ID",
System.Data.SqlDbType.Int, 4);
this.sqlCommand1.Parameters.Add("@Name",
System.Data.SqlDbType.VarChar, 50);
this.sqlCommand1.Parameters.Add("@Picture",
System.Data.SqlDbType.Image);
}
this.sqlCommand1.Parameters["@ID"].Value = this.editID.Text;
this.sqlCommand1.Parameters["@Name"].Value = this.editName.Text;
this.sqlCommand1.Parameters["@Picture"].Value = this.m_barrImg;
int iresult = this.sqlCommand1.ExecuteNonQuery();
MessageBox.Show(Convert.ToString(iresult));
|
|
|
|
|
Have you set the Connection property of sqlCommand1 ?
this.sqlCommand1.Connection = this.sqlConnection1;
I won’t not use no double negatives.
|
|
|
|
|
Thanks Philip
It Worked...
|
|
|
|
|
Hi all!
i want to fire an event to my application when ever i open or switch to other application.
for example: when i open word document, then the event should fire in my C# application. and when i change word document to another document then i need to get event.
need: i want to clear the clipbord data when the focus goes other than the internet explorer.
pls urgent... can anyone has any idea.
thanks in advance.
|
|
|
|
|
Here is two api GetForegroundWindow and GetWindowText for getting the title of forground window.
GetForegroundWIndow returns integer value. and pass it to GetWindowText.
Best Regard
If you can think then I Can.
|
|
|
|
|
Thanks for the reply.
i have already those two funcation. and i want to use that function while i past.
so my primary need is how to identify the past event.if i get the focus on the past event then i will use GetForegroundWindow and GetWindowText then i will decide whether to past or clear the clipboard.
do u have any idea on that !
thank you
Regards
.....Jack
|
|
|
|
|
you can use it by using hook.
Obvious you are changing application by Mouse or Keyboard.
By using hook u can check it in Keydown or mouse event.
Best Regard
If you can think then I Can.
|
|
|
|
|
Thanks !
if i dont get any other way then i will follow you.
and i too thought of that. but i was expecting some other ways.
Thanks for your idea.hope i will follow that.
thanks
Regards
.....Jack
|
|
|
|