Home > database >  Turn a Windows service, how to connect to the Oracle, and then operated the Oracle update table.
Turn a Windows service, how to connect to the Oracle, and then operated the Oracle update table.

Time:10-23

Webform application can normal connection Oracle, a reference to the same can't connect in a Windows service program, the linker and I to the operation of the database is written in the DBLayer;
RedSun Finance this two references of program execution to t_function_method. GetFXrateId (ssArray [1]), will not perform down, also don't error

Using System;
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Configuration;
Using System. The Data;
Using System. Diagnostics;
Using System. Linq;
Using System. ServiceProcess;
Using System. The Text;
Using System. The Timers;
Using System. IO;
Using System.Net;
//using DBLayer;
//using RedSun. Finance;

The namespace FxrateWS
{
Public partial class FxrateWS: ServiceBase
{
Public FxrateWS ()
{
InitializeComponent ();
}

//time to perform event
Private void TimedEvent (object sender, System. Timers. The ElapsedEventArgs e)
{
//business logic code

//RedSun. Finance. T_FXrate T_FXrate;
//RedSun. Finance. FunctionMethod t_function_method;
String l_get_content;
String [] sArray;
String [] ssArray;
//long l_FXrate_id;

L_get_content=GetContent (" https://dataapi.2rich.net/Quote/handler/Datas.ashx? Page=fx168 - RMB - jq& Vtype=XHWH ");

If (l_get_content. Length==0)
{
return;
}

SArray=l_get_content. Split (' # ');
SsArray=null;

List Listdata=https://bbs.csdn.net/topics/new a List ();

Foreach (string I in sArray)
{
Listdata. Add (I);
}

The foreach (string j in listdata)
{
SsArray=j.S plit (', ');

Wangdawei enclosing WriteLog (" ");

/* t_function_method=new FunctionMethod ();
If (t_function_method. GetFXrateId (ssArray [1],
The out l_FXrate_id
)==1)
{
Enclosing WriteLog (t_function_method p_error_string);
T_function_method=null;
return;
}
T_function_method=null;

If (l_FXrate_id & gt; 0)
{
T_FXrate=new t_FXrate ();
If (t_FXrate GetByKey (l_FXrate_id)==1)
{
T_FXrate. Release ();
T_FXrate=null;
return;
}
T_FXrate. P_BUY_REQUEST_QUOTE=the Convert. ToDecimal (ssArray [2]).
T_FXrate. P_SELL_REQUEST_QUOTE=the Convert. ToDecimal (ssArray [3]).
T_FXrate. P_UPDATE_TIME=ssArray [6].
If (t_FXrate. The Update ()==1)
{
T_FXrate. Release ();
T_FXrate=null;
return;
}
T_FXrate. Release ();
T_FXrate=null;
} */
}
}

Public string GetContent (string url)
{
//Get request in the request parameters, such as direct stitching in the url
WebRequest request=WebRequest. Create (url);

//return to Internet request response
WebResponse resp=request. The method GetResponse ();

//return data flow from network resources
The Stream Stream=resp. GetResponseStream ();

StreamReader sr=new StreamReader (stream, Encoding UTF8);

//the data flow on the string
The string result=sr. ReadToEnd ();

//close the stream data
Stream. The Close ();
The sr. The Close ();

return result;
}

Protected override void OnStart (string [] args)
{
System. The Timers. The Timer t=new System. Timers. The Timer (5000);//instantiate the Timer class, set the time interval for 1000 milliseconds.
T.E lapsed +=new System. The Timers. ElapsedEventHandler (TimedEvent);//to the execution time of events;
T.A utoReset=true;//set is to perform a (false) or has been performed (true);
T.E nabled=true;//whether the execution System. Timers. The Timer. Elapsed events;
T.S tart ();

Enclosing WriteLog (" FX168 data synchronization service: [service start] ");
}

Protected override void OnStop ()
{
Enclosing WriteLog (" FX168 data synchronization service: [service] ");
}

Private void WriteLog (string MSG)
{

//string path=@ "C: \ log. TXT";

//the log file is a Windows service program directory
String path=AppDomain. CurrentDomain. BaseDirectory + "\ \ log. TXT";
The FileInfo file=new the FileInfo (path);
if (! File. The Exists)
{
FileStream fs.
Fs=File. The Create (path);
Fs. The Close ();
}

Using (FileStream fs=new FileStream (path, FileMode. Append, FileAccess. Write))
{
Using (StreamWriter sw=new StreamWriter (fs))
{
Sw. WriteLine (DateTime. Now. The ToString () + "" + MSG);
}
}
}

}
}
  • Related