|
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<string> 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.
|
|
|
|
|
Hi,
Did you set the output type in project properties to Console Application? It's useful to have Console.Readline() as the final statement in the main method to prevent the window closing before you have read the contents.
Alan.
|
|
|
|
|
First of all make sure that you have created project by selecting proper project type and secondly put Console.Read(); statement at very end of your main method to put a pasue in execution.
|
|
|
|
|
Hi ,
I created a JOB Scheduling for Automatic DB backup in SQL server Agent using Microsoft.Sqlserver.Smo.
I followed all the step mentioned in msdn for creating job programmatically.
I used C# code for this.
Here are the step I used.
Create JOB object , Create Job Step then Job Scheduler.
Job is created everything is created successfully but when I see this job in Job Activity monitor it's next run date is coming null and Runnable option is coming No.Because of this my scheduler is not executing.
If I create a job manually through wizard the next date is populating and runnable is yes ad it is working fine. I did comparasion both of the jobs but didn't get any difference.
Can any one please help me to figure out this as I waste complete one day for this
Thanks in Advance
|
|
|
|
|
Hello EveryOne,
I really stuck in a place where I am desperately looking for the solution.
Can any one please help to figure out the problem.
Thanks,
Deepak
|
|
|
|
|
Hi,
I am currently Implementing a Tcp Server and a serial server which are running as services and receives events from a GUI based service controller through a message queue.
I wish to peek messages on the queue as the queue is shared by both the servers and i want the data to be received somewhere else.
I used the code provided at msdn for the asynchronous peek.
using System;
using System.Messaging;
namespace MyProject
{
public class MyNewQueue
{
public static void Main()
{
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
myQueue.PeekCompleted += new
PeekCompletedEventHandler(MyPeekCompleted);
myQueue.BeginPeek();
return;
}
private static void MyPeekCompleted(Object source,
PeekCompletedEventArgs asyncResult)
{
MessageQueue mq = (MessageQueue)source;
Message m = mq.EndPeek(asyncResult.AsyncResult);
Console.WriteLine("Message: " + (string)m.Body);
mq.BeginPeek();
return;
}
}
}
The problem is once a message is sent to the queue the peek event on service end fires perfectly, but keeps on firing for the same message. what i want is that the peek method should only fire once for any message received and then fires on consecutive message received, just like as a receive event works.
The problem lies somewhere in restarting the asynchronous peek and the logic involved in getting the messages.
Help Please!!!
|
|
|
|
|
The code you've posted doesn't have anything that removes the current message from the queue, so peeking will always return the same message. You either need to add something to receive messages from the queue (which will remove them), or use a message queue cursor to peek at messages past the first one.
|
|
|
|
|
Na na!!!
You miss judged my statements.
The problem is messages are coming conitinuously and i must use an asynchronous receive to trigger it on my application that a message has been received i don't wish to receive the messages but only peek at them, only when they are available in the queue. Peek only single message when it is available and then when the next is available peek at that and discard the older message which is intended to be received by some other service running after it.
So any work around that!!!
|
|
|
|
|
Right, I followed what you were saying. The problem is if you use Peek (or BeginPeek) without any arguments, it will always return the first message available in the queue. You must use a message queue cursor to move within the queue while peeking.
Here's some quick code to peek at all messages coming through the queue in a separate thread using a cursor.
public static void Main() {
queue = GetQueue();
ThreadPool.QueueUserWorkItem(new WaitCallback(QueueMonitor),queue);
}
void QueueMonitor(object SourceQueue) {
MessageQueue queue = (MessageQueue)SourceQueue;
Message msg = null;
Cursor cursor = queue.CreateCursor();
PeekAction action = PeekAction.Current;
try{
while(true) {
msg = queue.Peek(MessageQueue.InfiniteTimeout, cursor, action);
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessPeekedMessage), msg);
action = PeekAction.Next;
}
}catch(Exception ex){
}finally{
}
}
void ProcessPeekedMessage(object PeekedMessage) {
Message msg = (Message)PeekedMessage;
}
I opted to use the ThreadPool to run a thread instead of using the BeginPeek/AsyncCallback style. Someone here may have a better solution using that instead (from what I read, they're essentially doing the same thing). I also opted to thread the processing as well so the monitoring thread doesn't get blocked while the message is being worked on.
|
|
|
|
|
Hi everyone,
I am kind of just after a bit of advice and opinon. I am making a podcatcher in C#(duh that's the board I am posting to ). I don't have any problem with the coding yet(touch wood) however I am trying to decide how best to store the information on the subscribed to podcasts and their relevant episodes. Straight away I thought about saving it as an xml file, podcast RSS downloaded as an xml file, fairly easy convert of my object into XML and then back to saving it. But then I thought it could get a bit iffy when it comes to duplicates. I don't really want to have to traverse the entire XML doc to find duplicates, and ensure that they don't happen. So thinking ahead i created my podcast episode objects with a unique id. but then i don't really want to save my subscription list in a db either, that seems to me to be overkill. The only other thing is to just output the subs list into a text file, then read each object in and ensure that there are no duplicates from what ever storage container i put them in(ArrayList prob ) This seems a bit naff too though.
I don't know I think maybe I am just rubbish at making a decision , but I would appreciate some other people's input into how they would store the data.
Thanks in advance
Cads
|
|
|
|
|
Senseicads wrote: i don't really want to save my subscription list in a db either, that seems to me to be overkill
Go for a database with a small footprint. You can use SQL CE or Microsoft Access; both a relative small, and it would be easy to define a primary key or a unique-constraint
I are Troll
|
|
|
|
|
It just seems so OTT to use a Database to store what is basically RSS Feed data.
[edit]Although saying that I didn't think of using Access...hmmm...just not sure...
|
|
|
|
|
Senseicads wrote: It just seems so OTT to use a Database to store what is basically RSS Feed data.
Lots of RSS-data, and I guess that you want to search it fast
Senseicads wrote: Although saying that I didn't think of using Access
I'd go for SQL CE; it can't create nifty reports like Access does, but all that you need is a searchable datastore.
I are Troll
|
|
|
|
|
Lol I think you are right. I pretty much just need a datastore. Thanks for the guidance
Ian
|
|
|
|
|
My pleasure
|
|
|
|
|
SQL CE is obsolent. SQL Server Compact[^] is the current rendition
only two letters away from being an asset
|
|
|
|
|
Cool, thanks for the update
|
|
|
|
|
Eddy Vluggen wrote: Microsoft Access;
only two letters away from being an asset
|
|
|
|
|
Yeah, that's the standard-reaction, you get the some one when talking about Visual Basic 6. Many a brownfield is a combination of those two
Access empowered a lot of non-programmers to create small business-applications. It got abused as a server-database, and is still one of the better reporting engines (You'd only need to free runtime-version of Access and Microsoft Word)
Yeah, they were great products in their time, and they still haven't vanished.
I guess that they're like Windows, or Democracy. We know it sucks, but there is no better alternative available yet.
I are Troll
|
|
|
|
|
how many records will you need? 10? 100? 1000? simply don't know?
IMO for anything above 30 it takes a database to do it well. It's the most scalable approach. And it's easier than XML if you ask me.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I guess it would be fairly open ended as to how many podcasts that a user could subscribe to. I never really thought about how many records there would be( starting to sound like the amateur I am here! )
Actually thinking about my own usage, I am subscribed to about 10 different podcasts each with say 10-20 episodes in it. Certainly over your 30 records mark! lol
Is that a good rule of thumb? More than 30 use a db?
Thanks
Cads
|
|
|
|
|
Senseicads wrote: Is that a good rule of thumb? More than 30 use a db?
No it isn't. The real rule of thumb is: few ==> file; many ==> database. But that could be considered a bit vague. So I volunteered 30. Don't pin me down on the number.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
No from now on it will be Luc said 30!!! its too late now! its in print and everything!
|
|
|
|
|
Right. So start choosing your DB, your SQL dialect, your server, and your backup service.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I have this kind of error and I don't understand what can be the problem.
Is someone can help me to solved the problem or to understand what it's mean
Here is my code.
this.userinfos1.RoleID = mainData.roleid;
And this error message appears
NullReferenceException was unhandled
|
|
|
|