|
hi
i create a queue and service in my sql server 2005 by this code :
create queue myNotificationQueue
create service myService on queue myNotificationQueue
in my csharp code i wrote this code : (i copy this instance from msdn website)
class Program
{
string connstring = null;
SqlConnection conn = null;
SqlDataReader rdr = null;
static void Main(string[] args)
{
Program c = new Program();
c.connstring = @"Data Source=MYLAPTOP\SQLLAPTOP;Initial Catalog=pubs;Persist Security Info=True;User ID=sa;Password=1";
c.conn = new SqlConnection(c.connstring);
c.DoWork();
Console.ReadLine();
}
private void DoWork()
{
conn.Open();
rdr = GetJobs(2);
if (rdr != null)
{
rdr.Close();
WaitForChanges();
}
conn.Dispose();
}
public SqlDataReader GetJobs(int JobId)
{
using (SqlCommand cmd = new SqlCommand("Select job_id, job_desc from dbo. jobs where job_id = @id", conn))
{
try
{
cmd.Parameters.AddWithValue("@id", JobId);
SqlNotificationRequest not = new SqlNotificationRequest();
not.ID = new Guid(); // error occured
// this must be a service named MyService in the pubs database
// associated with a queue called notificationqueue (see below)
// service must go by QueryNotifications contract
not.Service = "myService"; // error occured
not.Timeout = 0;
// hook up the notification request
cmd.Notification = not;
rdr = cmd.ExecuteReader();
while (rdr.Read())
Console.WriteLine(rdr[0]);
rdr.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return rdr;
}
}
public void WaitForChanges()
{
// wait for notification to appear on the queue
// then read it yourself
using (SqlCommand cmd = new SqlCommand("WAITFOR (Receive convert(xml,message_body) from notificationqueue)", conn))
{
object o = cmd.ExecuteScalar();
// process the notification message however you like
Console.WriteLine(o);
}
}
}
but when i compile it, two following errors shown me :
System.Data.Sql.SqlNotificationRequest' does not contain a definition for 'ID'
System.Data.Sql.SqlNotificationRequest' does not contain a definition for 'Service'
How to solve my problem ?
thanks
|
|
|
|
|
Check this[^] out.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
thanks for reply
i corrected my code as following :
class Program
{
string connstring = null;
SqlConnection conn = null;
SqlDataReader rdr = null;
static void Main(string[] args)
{
Program c = new Program();
c.connstring = @"Data Source=MYLAPTOP\SQLLAPTOP;Initial Catalog=pubs;Persist Security Info=True;User ID=sa;Password=1";
c.conn = new SqlConnection(c.connstring);
c.DoWork();
Console.ReadLine();
}
private void DoWork()
{
conn.Open();
rdr = GetJobs();
if (rdr != null)
{
rdr.Close();
WaitForChanges();
}
conn.Dispose();
}
public SqlDataReader GetJobs()
{
using (SqlCommand cmd = new SqlCommand("Select job_id, job_desc from dbo.jobs", conn))
{
try
{
//cmd.Parameters.AddWithValue("@id", JobId);
SqlNotificationRequest not = new SqlNotificationRequest();
not.UserData = Guid.NewGuid().ToString();
// this must be a service named MyService in the pubs database
// associated with a queue called notificationqueue (see below)
// service must go by QueryNotifications contract
not.Options = "service=myService;local database=pubs";
not.Timeout = 0;
// hook up the notification request
cmd.Notification = not;
rdr = cmd.ExecuteReader();
while (rdr.Read())
Console.WriteLine(rdr[0]);
rdr.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return rdr;
}
}
public void WaitForChanges()
{
// wait for notification to appear on the queue
// then read it yourself
using (SqlCommand cmd = new SqlCommand("WAITFOR (Receive convert(xml,message_body) from myNotificationQueue)", conn))
{
cmd.CommandTimeout = 0;
object o = cmd.ExecuteScalar();
// process the notification message however you like
Console.WriteLine(o);
}
}
}
but in runtime, when i update any record in jobs table, my app was not reponse to that change (nothing occured),
where does my problem ?
|
|
|
|
|
Hello
I have an application wich runs with directx.
My problem is i'm new to directx and the thing which I want to create is pretty simple.
I want to load an image and then show it on the interface, then I want to get the events when the user clicks/mouse over/whatever on the picturebox.
I have tried a few tutorials on the internet but havent seen to find a thing which solves my problem.
I hope there is an easy way to do this, like an picturebox which can load the image easy.
if anyone knows a good article/tutorial/example on how to do this I would be happy.
//QzRZ
|
|
|
|
|
We have an application using MSMQ on the clients, and are investigating the possibility of having the server communicate with the clients using this mechanism.
The clients send messages to the server and the server send messages to the client (initiated from both sides). Messages are infrequent (could be many minutes from message to message), so I'd like to use async. messaging. This works well for local queues - is this also possible for a remote queue?
I have two options (our server will possibly be connected to 1000+ clients):
1. Create local queues on the server that client sends to, server uses beginPeek and other standards async. mechanisms for reading those queues. Then we'll have 1000s of queues all waiting at a beginPeek on the server? Is this possible in practice (remember infrequent messages)?
2. Use async. mechanisms to the remote queue (queue is on the client). I don't know how the underlying mechanism is, but this would possibly keep a connection open from the server to the client?
Any insight will be appreciated!
Jens Petter Abrahamsen
|
|
|
|
|
Forgive me for not thinking about this before:
The server would only need one (local) queue - and then determine which client sent the message by looking at the message. Thus, no need for 1000+ queues on the server. This local queue could of course use an asynchronous read mechanism if desirable.
I still don't know if it's possible to call async read functions on a remote queue, though, but this won't be necessary with the above alternative.
Jens Petter Abrahamsen
|
|
|
|
|
Hey all,
I am a relatively new programmer. Worked in the industry for about a year and a half as a junior and obviously college and uni before that.
I am looking for something fun to do, but also something that I could possibly display to other prospective employers, maybe something that could be of use for the development community. Does anyone have any ideas of what I could write in c# that would..
1. Be quite fun to develop
2. Be interesting an unusual that I could maybe blog about
3. Help me to learn more about fundamental processes and practices
I am basically a bit fed up with the usual run of the mill development I do here and am looking for a project that I could turn around to someone and say "hey, I did that".
Any idea's would be welcome.
Cheers.
|
|
|
|
|
daviiie wrote: 1. Be quite fun to develop
What do you find fun?
daviiie wrote: 2. Be interesting an unusual that I could maybe blog about
What do you regard as interesting?
daviiie wrote: 3. Help me to learn more about fundamental processes and practices
What do you need to learn?
If it is a website you could look at the Web Client Software Factory as it is part of the work by the pattens and practices group in Microsoft (lots of good processes to learn from that). If that doesn't interest you there are other projects from that group that might spark something.
|
|
|
|
|
Hi Colin,
I suppose I should have been more specific. By fun and interesting I would consider projects that use funky data structures or algorithms. I like stuff thats a little bit out of the box. I recently, just for the fun of it, developed an swi-prolog web service (the web service was already pre-written by swi, i'm not that good) to query a topic map database structure to dynamically assert facts which can in turn be queried by prolog and dumped out as xml which is picked up by a flex front end and displayed.
I will eventually get around to making some kind of simple natural language processor and inference engine type thing and get it hosted. As fun as that was though I consider it something that would be seen as a "hobbyist" computing activity that although would be an interesting thing to display at an interview isn't really that relevant when it comes to c# .net jobs.
I'd like something that utalizes c# in perhaps an unusual way, or to write a tool that perhaps would be very useful to other developers. A dll that I could open source and say "you know that thing that always annoys you when you program, well I've done something that sidesteps it...enjoy". I was thinking perhaps about some sort of encoding library because I am always running into problems with encodings and have yet to find something that makes my life easier.
Nice website by the way, I am a fellow Glasweigien although I don't currently live in the uk.
|
|
|
|
|
I have 2 column one textbox and the other is combobox
I want to select from the combo the ID appear in the text column and vis versa.
The data source is data set (not visual) for the combo column
this.column2.datasource= ds.table[0];
this.colomn2.dispalymember=ds.table[0].Rows[0][1];
this.colomn2.valuemember=ds.table[0].Rows[0][1];
merwa
|
|
|
|
|
Hi,
I want to send a mouseclick to a defined window in c#, without moving the cursor. It should just leftclick on a specified (X,Y) position on the screen.
Can i do that without moving the cursor?
And can it work if the target window is hidden/minimized?
Hope someone can give me a code example
|
|
|
|
|
Here you go!
[Flags]
public enum MouseEvent : uint
{
MOUSEEVENTF_MOVE = 0x0001,
MOUSEEVENTF_LEFTDOWN = 0x0002,
MOUSEEVENTF_LEFTUP = 0x0004,
MOUSEEVENTF_RIGHTDOWN = 0x0008,
MOUSEEVENTF_RIGHTUP = 0x0010,
MOUSEEVENTF_MIDDLEDOWN = 0x0020,
MOUSEEVENTF_MIDDLEUP = 0x0040,
MOUSEEVENTF_XDOWN = 0x0080,
MOUSEEVENTF_XUP = 0x0100,
MOUSEEVENTF_WHEEL = 0x0800,
MOUSEEVENTF_VIRTUALDESK = 0x4000,
MOUSEEVENTF_ABSOLUTE = 0x8000
}
public enum InputType : uint
{
INPUT_MOUSE = 0,
INPUT_KEYBOARD = 1,
INPUT_HARDWARE = 2
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
private InputType type;
public UInt32 dx;
public UInt32 dy;
public UInt32 mouseData;
public MouseEvent dwFlags;
public UInt32 time;
public IntPtr dwExtraInfo;
}
public static class MouseInput
{
[DllImport("User32.dll")]
public static extern UInt32 SendInput(UInt32 nInputs, MOUSEINPUT[] pInputs, int cbSize);
private static Point Normalize(Point pt)
{
return new Point((pt.X * 65535) / Screen.PrimaryScreen.Bounds.Width,
(pt.Y * 65535) / Screen.PrimaryScreen.Bounds.Height);
}
public static void Move(Point pt)
{
pt = Normalize(pt);
MOUSEINPUT[] input = new MOUSEINPUT[1];
input[0].dx = Convert.ToUInt32(pt.X);
input[0].dy = Convert.ToUInt32(pt.Y);
input[0].dwFlags = MouseEvent.MOUSEEVENTF_MOVE | MouseEvent.MOUSEEVENTF_ABSOLUTE;
SendInput(1, input, Marshal.SizeOf(input[0]));
}
public static void Click(Point pt)
{
Move(pt);
pt = Normalize(pt);
MOUSEINPUT[] input = new MOUSEINPUT[2];
input[0].dx = Convert.ToUInt32(pt.X);
input[0].dy = Convert.ToUInt32(pt.Y);
input[0].dwFlags = MouseEvent.MOUSEEVENTF_LEFTDOWN | MouseEvent.MOUSEEVENTF_ABSOLUTE;
input[1].dx = Convert.ToUInt32(pt.X);
input[1].dy = Convert.ToUInt32(pt.Y);
input[1].dwFlags = MouseEvent.MOUSEEVENTF_LEFTUP | MouseEvent.MOUSEEVENTF_ABSOLUTE;
SendInput(2, input, Marshal.SizeOf(input[0]));
}
} To simulate a click at 100,100 therefore you'd do this:
MouseInput.Click( new Point( 100, 100 ) ); I don't think you can do it without moving the cursor. You could save the current mouse position, click at the point where you want to click and then move right back to the saved position!
|
|
|
|
|
Hi,
Almost forgot to thank you! So.. Thanks!
Nice code
|
|
|
|
|
Hey all,
I think it is possible to reset windows password through c#, but would it be possible to compare windows password to verify the user identity?
With System.Security.Principal i can get the current windows identity but i just want to verify that the person in front of the comptuter is the real user.
In case it is not possible, just for security concerns how could i approach it?
thanks in advance...
Luis E Tineo S
|
|
|
|
|
Hi,
I guess you should search on Active Directory Services Interface (ADSI).
Regards,
Adeel
|
|
|
|
|
Hi everybody,
it exists seriously a function which stops the current time, or maybe a whole "stopwatch"-class
which calculates the time between a start and a stop...
If not, how can i use the clock() function of C/C++? It's declared into time.h
Big thanks for help
|
|
|
|
|
If your time measurement doesn't require to be very precise then you can do something like this:
<br />
DateTime starttime=DateTime.Now;<br />
DoWork();<br />
DateTime endtime=DateTime.Now;<br />
The difference between endtime and starttime will show you the duration between two moments.
However, if your measurements need to be precise then I suggest you use Stopwatch Class[^]
|
|
|
|
|
Thanks for your reply
I'll test DateTime, simple but effective
Since 1year no more coded in C# and i forgot the basic classes like DateTime ... ouch LOL
|
|
|
|
|
You are welcome
|
|
|
|
|
How can i parse a c# code?
i found "SysyTem.CodeDom.Compiler.CodeDomProvider" class which have method called "Parse" but is gives me an exception that this method is not implemented, this method is what i want.
any help??
Essam
|
|
|
|
|
Ya3sam wrote: How can i parse a c# code?
What do you mean by "parse a c# code?" Are you trying to parse a file full of strings? Are they fixed-width fields, delimited, do they use CR and/or LF?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I think he wants parser of C# language.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
How about you check out the documentation[^]?
Ya3sam wrote: is gives me an exception that this method is not implemented
From the docs: "Provides a base class for CodeDomProvider implementations. This class is abstract." Of course it throws not implemented exception, it's the base class. Follow the provided link, there is example how to parse code.
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Where is the link please?
Essam
|
|
|
|
|
It's word "documentation" in first sentence of my previous post. Click on it
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|