|
It's actually a bull, and I hadn't looked at it that way. Now I'm sure I won't be able not to.
|
|
|
|
|
You could simply do it by hand, creating a new connection is a pretty simple task.
myCommand.Connection = new SqlConnection("...Connection String...")
If you do a quick web search for connection strings for your specific database, you should be able to set that up in no time.
|
|
|
|
|
I would make the clas SQLDBConnect a static class. I would also give it a method that returns a connection
SqlConnection conn=new SqlConnection();
SqlCommand comm=new SqlCommand();
conn.ConnectionString=SQLDBConnection.getConnectStr();
conn.Open();
comm.Connection=conn;
|
|
|
|
|
Hi,
I would like to code a TCP/UDP server and I've coded a major part of it but it seems like if the server is busy, then I will have a problem.
Here is my Listening code:
private void Listen()
{
Console.WriteLine( "Listening port " + port.ToString() +"." );
listener.Start();
while (KeepWorking)
{
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("---------------------");
Console.WriteLine(client.Client.RemoteEndPoint.ToString() + " connected.");
ClientHistory.Add( client.Client.RemoteEndPoint.ToString() );
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleCommunication), client);
}
}
If more than one client requests to connect at the same time then one won't be able to connect because I am not listening.
If a client connects and before it's queued to ThreadPool another client wants to connect, it won't be able to connect because I am not listening again.
Is there a way to solve this or is this how every server works?
Thanks.
modified on Tuesday, January 26, 2010 5:24 AM
|
|
|
|
|
From the documentation[^]
"Start will queue incoming connections until you either call the Stop method or it has queued MaxConnections"
That's still open to multiple interpretations.. but I think it means that your problem does not exist because it keeps queuing new connections when you're not blocking on Accept.
Anyway, even if it didn't work that way, the time window in which it can go wrong is infinitesimal, unless ClientHistory.Add does something other than expected (maybe do a blocking write to a logfile or so.. it looks like adding to a List<string> )
|
|
|
|
|
OK, let's assume that I've deleted all those ClientHistory lines. It still seems like two clients can't connect at the exact same time. Between AcceptTcpClient() and QueueUserWorkItem(), server doesn't accept new connections for miliseconds.
|
|
|
|
|
Does it really happen between them, or sometime after the QueueUserWorkItem?
Does the connection handler send/receive any data?
A NIC can only do 1 thing at once so during the send/receive no one can connect (they will be delayed)
|
|
|
|
|
I've never experienced this problem I am talking about. As assumed that, if enough number of clients try to connect this server, they wouldn't be able to.
|
|
|
|
|
Ok, well I was in a good mood and decompiled TcpListener.Start for you.
public void Start()
{
this.Start(0x7fffffff);
}
public void Start(int backlog)
{
if ((backlog > 0x7fffffff) || (backlog < 0))
{
throw new ArgumentOutOfRangeException("backlog");
}
if (Logging.On)
{
Logging.Enter(Logging.Sockets, this, "Start", (string) null);
}
if (this.m_ServerSocket == null)
{
throw new InvalidOperationException(SR.GetString("net_InvalidSocketHandle"));
}
if (this.m_Active)
{
if (Logging.On)
{
Logging.Exit(Logging.Sockets, this, "Start", (string) null);
}
}
else
{
this.m_ServerSocket.Bind(this.m_ServerSocketEP);
this.m_ServerSocket.Listen(backlog); <--- !!see here!!
this.m_Active = true;
if (Logging.On)
{
Logging.Exit(Logging.Sockets, this, "Start", (string) null);
}
}
}
So the result is a call to SomeSocket.Listen(int.MaxValue) , which according to the documentation[^]: "Places a Socket in a listening state. Int32 backlog: The maximum length of the pending connections queue."
In other words, don't worry, the connections are being placed in the backlog. Of course it can happen that connections are being made at a faster rate than you can handle them, which is really just a denial of service attack. You can't do anything about that, no matter how many connections per second you can handle, they could just throw 1 more at you and you'd lose.
So it all comes down to "magic happens in the background in code that you didn't write", in a more theoretical setting in which connections are only accepted while you are waiting for them, you would have a theoretical problem. Fortunately real world sockets don't work that way
|
|
|
|
|
Thank you. I know understand it all.
|
|
|
|
|
Does anyone have a good solution for integrating some C# code into a java application?
without using web services. is ther any way to integration java files using c#
try and try untill reach success..
|
|
|
|
|
You may find some converter tools if you search on the internet.
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
thanks Abhinav, i found there is a third party tool called GrassHopper, but i dont want to use any third party tool.
try and try untill reach success..
|
|
|
|
|
Rajeshwar Code- Developer wrote: Does anyone have a good solution for integrating some C# code into a java application?
without using web services. is ther any way to integration java files using c#
You seem to have posed your question from both sides. Do you want to use a Java application from within a C# app, or do you want to call a C# library from Java?
MVP 2010 - are they mad?
|
|
|
|
|
i want to use java application
try and try untill reach success..
|
|
|
|
|
Rajeshwar Code- Developer wrote: i want to use java application
Well that was clear from your original post. How do you want to use it, do you
i) have a Java application that needs to use the facilities of a C# library, or
ii) hava a C# application that wants to load and run a Java Virtual machine to get access to some Java features?
Please try and state your requirements clearly.
MVP 2010 - are they mad?
|
|
|
|
|
actually this question asked in one of the interviewer so .i wnat to know actually what is the answer.
try and try untill reach success..
|
|
|
|
|
Rajeshwar Code- Developer wrote: actually this question asked in one of the interviewer so .i wnat to know actually what is the answer.
Liquid Nitrogen!
MVP 2010 - are they mad?
|
|
|
|
|
I'll explain to you the easy way why this is a bad method to make a good application.
It's like in the morning when you want to eat breakfast, you can chose between some plums (Java) or a glass of milk (C#). What happens when you mix this two.. don't try it!
A good practice: eat only the glass of milk
Cheer's,
Alex Manolescu
|
|
|
|
|
when i finished my project and published it
then when i begin to report,it shows:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'CrystalDecisions.Windows.Forms, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies.
i use VS2008 and crystal report 2008,i do not know how to do ?
|
|
|
|
|
You need to install the crystal reports framework.
Do a search for the merge modules on the crystal reports site.
|
|
|
|
|
How to right-to-left and change language(i wanna persian Language for it) of MS Agent ?
|
|
|
|
|
|
I was fighting a similar issue yesterday night...
There is a memory leak happening. every time you create a curson, there is new object being created. Checkout in TaskManager... Number of GDIobjects and UserObjects go to a damn high.
check out this tutorial:
http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors[^]
In the comments, User: Aerdanel has sorted the memory leaks. Use the same method for your custom cursor.
Som
|
|
|
|
|
did you remove the message?
|
|
|
|