473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

System.Net.Sockets.SocketException

Hi all,

i have a console app set up as a scheduled task which does a couple of different things

First it connects to the SQL Server and performs a simple query, then it launches a web page based on the query results. (the web page is ASP served from the same machine)

Both IIS and SQL Server are on the same machine that will have the scheduled task running.

I am developing the app on a separate machine, and when i run it it does everything correctly.....goes off to the server, connects to SQL , gets a results dataset back, then goes off to the web page and feeds it the data.

When i copy the app to the server though, i get :
Unhandled Exception: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it


Any pointers on why i would be able to connect remotely, but not locally?

i am new to developing in .NET so i could well have forgotten to copy a file over, or maybe i need to configure something else....i dont know....HELP!
i have basically just copied the whole BIN/RELEASE directory over to the server machine....that should have everything it needs shouldn't it?
Sep 10 '07 #1
2 1174
code :

Expand|Select|Wrap|Line Numbers
  1.    class doMyCheck
  2.     {
  3.         static void Main()
  4.         {
  5.             string field1, field2, connstring = "", sql;
  6.             SqlConnection c;
  7.             SqlCommand sqlcommand;
  8.             SqlDataAdapter sqldataadapter;
  9.             DataSet dataset;
  10.             DataTable datatable;
  11.             int id;
  12.  
  13.             connstring += "data source=MYSERVER;";
  14.             connstring += "user id=**********;";
  15.             connstring += "password=************;";
  16.             connstring += "initial catalog=**********************;";
  17.  
  18.             c = new SqlConnection();
  19.             c.InfoMessage += new SqlInfoMessageEventHandler(OnInfoMessage);
  20.             c.StateChange += new StateChangeEventHandler(OnStateChanged);
  21.             c.ConnectionString = connstring;
  22.             c.Open();
  23.  
  24.             if (c.State == ConnectionState.Open)
  25.             {
  26.                 sql = "SELECT * from view**********************";
  27.                 sqlcommand = new SqlCommand();
  28.                 sqlcommand.Connection = c;
  29.                 sqlcommand.CommandText = sql;
  30.                 sqlcommand.CommandType = CommandType.Text;
  31.                 sqldataadapter = new SqlDataAdapter();
  32.                 sqldataadapter.SelectCommand = sqlcommand;
  33.                 dataset = new DataSet();
  34.                 sqldataadapter.Fill(dataset);
  35.                 datatable = dataset.Tables[0];
  36.                 string baseURL = "http://www.***********.com/myPage.asp";
  37.                 string postData;
  38.                 foreach (DataRow drow in datatable.Rows)
  39.                 {
  40.                     id = (int)drow[0];
  41.                     field1 = drow[1].ToString();
  42.                     field2 = drow[2].ToString();
  43.                     Print(id.ToString(), 6);
  44.                     Print(field1, 20);
  45.                     Print(field2.ToString(), 6);
  46.                     postData = "id=" + id.ToString();
  47.                     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseURL);
  48.                     req.Method = "POST";
  49.                     ASCIIEncoding encoding = new ASCIIEncoding();
  50.                     byte[] byte1 = encoding.GetBytes(postData);
  51.                     req.ContentType="application/x-www-form-urlencoded";
  52.                     req.ContentLength = postData.Length;
  53.                     Stream newStream = req.GetRequestStream();
  54.                     newStream.Write(byte1, 0, byte1.Length);
  55.                     Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", req.ContentLength);
  56.                     newStream.Close();
  57.                 }
  58.                 datatable = null;
  59.                 sqldataadapter = null;
  60.                 sqlcommand = null;
  61.                 c.Close();
  62.             }
  63.             c = null;
  64.             Console.Read();
  65.         }
  66.         protected static void OnStateChanged(object sender, StateChangeEventArgs e)
  67.         {
  68.             Console.WriteLine(
  69.                 "sql server state is -> {0}",
  70.                 e.CurrentState.ToString("g")
  71.             );
  72.         }
  73.         protected static void OnInfoMessage(object sender, SqlInfoMessageEventArgs e)
  74.         {
  75.             foreach (SqlError err in e.Errors)
  76.             {
  77.                 Console.WriteLine(err.Message);
  78.             }
  79.         }
  80.         static void Print(string towrite, int maxlen)
  81.         {
  82.             if (towrite.Length >= maxlen)
  83.             {
  84.                 Console.Write(towrite.Substring(0, maxlen - 4) + "... ");
  85.                 return;
  86.             }
  87.             towrite += new string(' ', maxlen - towrite.Length);
  88.  
  89.             Console.Write(towrite);
  90.         }
  91.     }
Sep 10 '07 #2
Plater
7,872 Expert 4TB
So it's the SQL part that creates the socket exception and not the website one?

It would be a bit abnormal for this to happen, but is your SQL server setup to allow local connections (via "named pipes" probably)??
Only other thing I can think of is something to do with permisions for the credentials that your application is running on need to be set correctly.
Sep 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: paulbubach | last post by:
Hi @all, we have the following problem. We have developed an application with the Visual Studio.Net 2002 and the project runs on it. But now we have change the version of the Studio and now we...
4
by: Sagaert Johan | last post by:
i get this error if i write this : using System.Net.Sockets; .... .... TcpClient tcp; tcp=new TcpClient();
0
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
0
by: vincent | last post by:
Hi all, I'm getting this error when i running my applicaion with remote server from my local machine. An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in...
2
by: Steve Lowe | last post by:
Hi, I have a VB.Net 2003 program that uses Indy to check if there are any messages waiting on a POP mail server. The program has been running fine for a few months, but last week after...
4
by: sd1978 | last post by:
Hi, I have placed a webservice in the webserver. When I access it from a webpage, default.aspx on a click of a button i get the following error: No connection could be made because the target...
5
by: PJ6 | last post by:
I can't figure this out. I have several references to style sheets and javascript files in my page header, the contents of which are served dynamically by my httphandler that serves *.res requests....
1
by: larspeter | last post by:
Hi all. I have a problem with TcpClient ... I am conneting to a server with TcpClient and returning the answer through a webservice. It actully all works fine. BUT if I make a lot of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.