المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : using console application as service



C# Programming
09-17-2009, 07:02 AM
hello;

I have a problem using console application.I mostly use Windows application. I m using C# 2005 and Sql server2005 as part of my project.I am using 3layered architecture i have method in Business class:

public static int DataSelectionForAutoGeneratedMsg(string strTableName, out List strContactNos)
Because i have to check that if a customer has his reservation booked for next day then he should be reminded for that.For that our service (which i m intended to built using console app) keep checking in the reservation table having columns(cust_id,reservation_date,service_name) .

then if the result of the query is correct i.e if it returns datatable then it has to send sms to that customer.Below is the code but i have not included the coding for sending sms here.Instead of that i have just used the Console.Writeline statement so that atlaest this par works


also i have not included the coding of internal class ConnectionString
Hope the information will be enough for u to understand

Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;
using System.Data.SqlClient;
using HRCF.BL;// adding Business logic
using HRCF.DB;//adding database
using System.ComponentModel;

namespace ConsoleApp_service
{
public class services

{

//private CHRCFDB m_objCHRCFDB = null;
public services()
{
//m_objCHRCFDB = new CHRCFDB();

}
static void Main(string[] args)
{
Console.WriteLine("Reading this line");
//dont kno wheather th efollowing line of code is correct or not.It gives no error but no output as well!!
string result = Checkingreservation("reservation", out dtTableRecords_out);
}


public static string CheckingReservation(string strTableName, out DataTable dtTableRecords_out)
{

string strQueryString = "";
SqlCommand objSqlCommand = null;
SqlConnection objSqlConnection = null;
DataSet objDataSet = null;
SqlDataAdapter objDataAdapter = null;
// checking from the current date
string ritenow = Convert.ToString(System.DateTime.Now);

try
{
objDataSet = new DataSet();
objDataAdapter = new SqlDataAdapter();
objSqlConnection = new SqlConnection(ConnectionString.GetSQLConnectionString());
strQueryString = "select cust_id,ser_name from reservation where date = " + ritenow;
objSqlCommand = new SqlCommand(strQueryString, objSqlConnection);

objDataAdapter.SelectCommand = objSqlCommand;
objSqlConnection.Open();
objDataSet.Clear();

objDataAdapter.Fill(objDataSet);
objSqlConnection.Close();
dtTableRecords_out = objDataSet.Tables[0];


if (dtTableRecords_out != null)
{
Console.WriteLine("Service is reserved for today");
}
else
{
Console.WriteLine("No reservation for today");
}
}
finally
{
if (objSqlConnection.State == ConnectionState.Open)
{
objSqlConnection.Close();
}

}
return strQueryString;




}

}
}


I am unable to find any error.When i debug it then nothing happens no black window instead of it an empty form appears.