webform的程式可以正常連接Oracle,同樣的參考在Windows服務程式中就連接不了。連接程式和對資料庫的操作我時寫在DBLayer;
RedSun.Finance 這兩個參考中的,程式執行到 t_function_method.GetFXrateId(ssArray[1]),往下就不執行了,也不報錯
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using System.Net;
//using DBLayer;
//using RedSun.Finance;
namespace FxrateWS
{
public partial class FxrateWS : ServiceBase
{
public FxrateWS()
{
InitializeComponent();
}
//定時執行事件
private void TimedEvent(object sender, System.Timers.ElapsedEventArgs e)
{
//業務邏輯代碼
//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<string> listdata = new List<string>();
foreach (string i in sArray)
{
listdata.Add(i);
}
foreach (string j in listdata)
{
ssArray = j.Split(',');
this.WriteLog("wangdawei");
/*t_function_method = new FunctionMethod();
if (t_function_method.GetFXrateId(ssArray[1],
out l_FXrate_id
) == -1)
{
this.WriteLog(t_function_method.p_error_string);
t_function_method = null;
return;
}
t_function_method = null;
if (l_FXrate_id > 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 = Convert.ToDecimal(ssArray[2]);
t_FXrate.p_SELL_REQUEST_QUOTE = Convert.ToDecimal(ssArray[3]);
t_FXrate.p_UPDATE_TIME = ssArray[6];
if (t_FXrate.Update() == 1)
{
t_FXrate.Release();
t_FXrate = null;
return;
}
t_FXrate.Release();
t_FXrate = null;
}*/
}
}
public string GetContent(string url)
{
//Get請求中請求引數等直接拼接在url中
WebRequest request = WebRequest.Create(url);
//回傳對Internet請求的回應
WebResponse resp = request.GetResponse();
//從網路資源中回傳資料流
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
//將資料流轉換文字串
string result = sr.ReadToEnd();
//關閉流資料
stream.Close();
sr.Close();
return result;
}
protected override void OnStart(string[] args)
{
System.Timers.Timer t = new System.Timers.Timer(5000);//實體化Timer類,設定間隔時間為1000毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(TimedEvent);//到時間的時候執行事件;
t.AutoReset = true;//設定是執行一次(false)還是一直執行(true);
t.Enabled = true;//是否執行System.Timers.Timer.Elapsed事件;
t.Start();
this.WriteLog("FX168資料同步服務:【服務啟動】");
}
protected override void OnStop()
{
this.WriteLog("FX168資料同步服務:【服務停止】");
}
private void WriteLog(string msg)
{
//string path = @"C:\log.txt";
//該日志檔案會存在windows服務程式目錄下
string path = AppDomain.CurrentDomain.BaseDirectory + "\\log.txt";
FileInfo file = new FileInfo(path);
if (!file.Exists)
{
FileStream fs;
fs = File.Create(path);
fs.Close();
}
using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(DateTime.Now.ToString() + " " + msg);
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/31358.html
標籤:開發
下一篇:Unexpected runtime exception while delivering HashStructureHookEvent
