|
I don't know what info do you need.
I've opened two different form Application projects one is server the other is client.
When I hit "Run" in order to start server to listen, an error pops up as written in the title.
The reason must be that I don't know exactly how to make run the project correctly, in other words how to run correctly the server and after that the client.
P.S. I did it exactly like I use to do in Java (eclipse), but here it seems to be need to be done differently.
|
|
|
|
|
You say "When I hit run" but you do not say if this is the 'Run' button/Menu in VS or something on one of your Forms.
This error occurs when the Framework is unable to find an assembly referenced somewhere in your code. Sometimes due to an explicit call to Assembly.Load or LoadFrom , so do you make any calls like that. More often it is because it cannot find an assembly that is in your 'Usings' section, so are you using any third-party dlls (I say third-party because Framework dlls should be in the GAC and would be found.).
If it is a third-party dll that is causing the problem, this[^], may help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
 I mean the 'Run' button/Menu in VS.
I don't use any third-party dlls.
Here is a code of Program class - the server, please tell me what you think:
<pre lang="cs">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
static class Program
{
private static bool listening = false;
private static TcpListener myList;
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ConnectionForm());
IPAddress ipAd = IPAddress.Parse("localhost");
myList = new TcpListener(ipAd, 8001);
listening = true;
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
while (listening)
{
try
{
Console.WriteLine("The server is running at port 8001...");
Console.WriteLine("The local End point is :" +
myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.....");
Socket clientSocket = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + clientSocket.RemoteEndPoint);
new Client_sThresds(clientSocket);
myList.Start();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
myList.Stop();
}
}
}
}
modified on Saturday, February 12, 2011 3:06 PM
|
|
|
|
|
Before I get to your code, you should surround your code with
<pre lang="cs">
your code goes here
...................
</pre>
tags. This will preserve your indentation and uses some syntax colourization, all of which makes it easier to read.
Since your code does not seem to make any use of ConnectionForm and, in fact, places all output to the Console I would try making this a Console Application not a Windows Forms Application. This may not actually cure the problem but will reduce the size of the compiled application considerably, a good thing for a server application.
I can see nothing that is obviously wrong with with your code but you did not include the 'usings' section, which may be where the problem lies.
Most server apps like this have a very limited set of usings, something like:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
If you have more than these then you could also try using the right-click menu to Organize Usings|Remove Unused Usings.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
edited it in previous post usings included
|
|
|
|
|
OK, now I'm really confused.
Your usings do not include System.Net nor System.Net.Sockets and yet you use, according to your code
private static TcpListener myList;
/pre>
That is not possible.
Either the usings you posted are incorrect or you have edited your code, not pasted it directly.
<div class="signature">Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
"I want to report a fraud. The government is lying to us all."
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.</div>
|
|
|
|
|
Sorry my bad , here the true ones:
using System;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
|
|
|
|
|
I have created a project using your code and I cannot get the error that you are getting.
I had to comment out one line as it gave compile errors and I could not find any reference to it despite a thorough internet search.
That line was:
new Client_sThresds(clientSocket);
so it could well be that whatever that is, is the cause of your problem.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
It's because you don't have that class.
Just comment that line, and try to run without it.
modified on Saturday, February 12, 2011 8:24 PM
|
|
|
|
|
Marat Beiner wrote: Just comment that line, and try to run without it.
As I said in my previous post, I did.
I could not get the error that you are getting.
I can only suggest that you copy the entire error message and paste it into the search box on your favourite search engine. It may be that someone else has had the same problem and posted about it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
I tried it before, found nothing helpful, thanks anyway.
|
|
|
|
|
Hi everyone,
I have developed a desktop application. I have created a menu item to click for backup database from MS SQL Server 2005. This is why I have created a method to perform the operation. But the method is not working well. There’s something wrong in the code which I cannot recognize. Please help me to find the problem and solution as well. The method code is given bellow:
public void BackupDatabase(String databaseName, String destinationPath)
{
try
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
SqlConnection sqlCon = new SqlConnection(GenericDataAccess.GetConnectionString());
ServerConnection connection = new ServerConnection(sqlCon);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlServer.Databases.Add(db);
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
}
}
And the click event from where I am calling the method is also given:
private void backupMnuItem_Click(object sender, EventArgs e)
{
BackupData_Bl backup = new BackupData_Bl();
backup.BackupDatabase("CFM", "D:\\TEMP");
}
For your information (it might help you to find the problem) I have first create my database using SQL Server Management Studio. Then I’ve move the database from sql server installation location to my project directory under a folder named DB. After that I have attached the database using SQL Server Management Studio.
|
|
|
|
|
And the error you get is?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Please don't post this sort of thing here; this is a technical forum, let's keep it that way.
I must get a clever new signature for 2011.
|
|
|
|
|
Reported as spam in sugs&bugs: he posted the same in the Java forum as well...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
I am working in c# i want to apply the timer on the buttons or want to change their colour randomly from green to red after certain time.I dont want all the buttons to change the color from green to red at the same time i.e if there are three buttons then then they can change colour from green to red at different time periods. Is there any function to do this???
|
|
|
|
|
Subclass Button and wrap a Timer exposing the properties and methods of it that you need.
Something like this - just set ColorA , ColorB and Interval then call Start .
using System;
using System.Drawing;
using System.Windows.Forms;
public class ColoredButton : Button
{
public static readonly Color DefaultColorA = Color.Red;
public static readonly Color DefaultColorB = Color.Green;
public const int DefaultInterval = 1000;
public event EventHandler Tick;
private Color colorA;
private Color colorB;
private Timer timer;
public ColoredButton()
{
colorA = DefaultColorA;
colorB = DefaultColorB;
BackColor = colorA;
timer = new Timer();
timer.Interval = DefaultInterval;
timer.Tick += TimerTick;
}
public Color ColorA
{
get { return colorA; }
set { colorA = value; }
}
public Color ColorB
{
get { return colorB; }
set { colorB = value; }
}
public int Interval
{
get
{
if (timer != null)
return timer.Interval;
else
return DefaultInterval;
}
set
{
if (timer != null)
timer.Interval = value;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && timer != null)
{
timer.Dispose();
timer = null;
}
base.Dispose(disposing);
}
protected virtual void OnTick(EventArgs e)
{
EventHandler eh = Tick;
if (eh != null)
eh(this, e);
}
public void Start()
{
if (timer != null)
timer.Start();
}
public void Stop()
{
if (timer != null)
timer.Stop();
}
private void TimerTick(object sender, EventArgs e)
{
if (BackColor == colorA)
BackColor = colorB;
else
BackColor = colorA;
OnTick(EventArgs.Empty);
}
}
|
|
|
|
|
Thanks. But where should i put this code. i have a form and have placed button on it. So i want that whenever i run the program this code should work
|
|
|
|
|
You would create a new class called ColoredButton and place this code in there.
Build the application, then replace the buttons with these - a ColoredButton control will have appear in the toolbox.
|
|
|
|
|
 I have creadted a class and when build its giving errors
Here is the code
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class ColoredButton
{
public static readonly Color DefaultColorA = Color.Red;
public static readonly Color DefaultColorB = Color.Green;
public const int DefaultInterval = 1000;
public event EventHandler Tick;
private Color colorA;
private Color colorB;
private Timer timer;
public ColoredButton()
{
colorA = DefaultColorA;
colorB = DefaultColorB;
BackColor = colorA;
timer = new Timer();
timer.Interval = DefaultInterval;
timer.Tick += TimerTick;
}
public Color ColorA
{
get { return colorA; }
set { colorA = value; }
}
public Color ColorB
{
get { return colorB; }
set { colorB = value; }
}
public int Interval
{
get
{
if (timer != null)
return timer.Interval;
else
return DefaultInterval;
}
set
{
if (timer != null)
timer.Interval = value;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && timer != null)
{
timer.Dispose();
timer = null;
}
base.Dispose(disposing);
}
protected virtual void OnTick(EventArgs e)
{
EventHandler eh = Tick;
if (eh != null)
eh(this, e);
}
public void Start()
{
if (timer != null)
timer.Start();
}
public void Stop()
{
if (timer != null)
timer.Stop();
}
private void TimerTick(object sender, EventArgs e)
{
if (BackColor == colorA)
BackColor = colorB;
else
BackColor = colorA;
OnTick(EventArgs.Empty);
}
}
}
Errors:
Error 1 The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Documents and Settings\XPPRESP3\Local Settings\Application Data\Temporary Projects\ClassLibrary1\ColoredButton.cs 4 14 ClassLibrary1
Error 2 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Documents and Settings\XPPRESP3\Local Settings\Application Data\Temporary Projects\ClassLibrary1\ColoredButton.cs 5 14 ClassLibrary1
Error 3 The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\XPPRESP3\Local Settings\Application Data\Temporary Projects\ClassLibrary1\ColoredButton.cs 15 32 ClassLibrary1
|
|
|
|
|
The errors give you the answer!
In your ClassLibrary1 project, in Solution Explorer, right click on References, choose Add Reference and under the .NET tab click System.Drawing and click OK. Repeat for System.Windows.Forms.
There is no need to post the same reply twice by the way
|
|
|
|
|
Thanks a lot. A class has been successfully created but when i create a from and the colored button control does not appear in the tool box.
|
|
|
|
|
 I have created the class but its giving me errors when i build the application:
here is the code
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class ColoredButton
{
public static readonly Color DefaultColorA = Color.Red;
public static readonly Color DefaultColorB = Color.Green;
public const int DefaultInterval = 1000;
public event EventHandler Tick;
private Color colorA;
private Color colorB;
private Timer timer;
public ColoredButton()
{
colorA = DefaultColorA;
colorB = DefaultColorB;
BackColor = colorA;
timer = new Timer();
timer.Interval = DefaultInterval;
timer.Tick += TimerTick;
}
public Color ColorA
{
get { return colorA; }
set { colorA = value; }
}
public Color ColorB
{
get { return colorB; }
set { colorB = value; }
}
public int Interval
{
get
{
if (timer != null)
return timer.Interval;
else
return DefaultInterval;
}
set
{
if (timer != null)
timer.Interval = value;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && timer != null)
{
timer.Dispose();
timer = null;
}
base.Dispose(disposing);
}
protected virtual void OnTick(EventArgs e)
{
EventHandler eh = Tick;
if (eh != null)
eh(this, e);
}
public void Start()
{
if (timer != null)
timer.Start();
}
public void Stop()
{
if (timer != null)
timer.Stop();
}
private void TimerTick(object sender, EventArgs e)
{
if (BackColor == colorA)
BackColor = colorB;
else
BackColor = colorA;
OnTick(EventArgs.Empty);
}
}
}
Errors:
The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\XPPRESP3\Local Settings\Application Data\Temporary Projects\ClassLibrary1\ColoredButton.cs 40 16 ClassLibrary1
Error 1 The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Documents and Settings\XPPRESP3\Local Settings\Application Data\Temporary Projects\ClassLibrary1\ColoredButton.cs 4 14 ClassLibrary1
|
|
|
|
|
i m working in c#.How to insert values in text box at run time in window application and compare it with the int.can any one tell me.any help will be appreciated.
Thamks
|
|
|
|