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?
2 1174
code : - class doMyCheck
-
{
-
static void Main()
-
{
-
string field1, field2, connstring = "", sql;
-
SqlConnection c;
-
SqlCommand sqlcommand;
-
SqlDataAdapter sqldataadapter;
-
DataSet dataset;
-
DataTable datatable;
-
int id;
-
-
connstring += "data source=MYSERVER;";
-
connstring += "user id=**********;";
-
connstring += "password=************;";
-
connstring += "initial catalog=**********************;";
-
-
c = new SqlConnection();
-
c.InfoMessage += new SqlInfoMessageEventHandler(OnInfoMessage);
-
c.StateChange += new StateChangeEventHandler(OnStateChanged);
-
c.ConnectionString = connstring;
-
c.Open();
-
-
if (c.State == ConnectionState.Open)
-
{
-
sql = "SELECT * from view**********************";
-
sqlcommand = new SqlCommand();
-
sqlcommand.Connection = c;
-
sqlcommand.CommandText = sql;
-
sqlcommand.CommandType = CommandType.Text;
-
sqldataadapter = new SqlDataAdapter();
-
sqldataadapter.SelectCommand = sqlcommand;
-
dataset = new DataSet();
-
sqldataadapter.Fill(dataset);
-
datatable = dataset.Tables[0];
-
string baseURL = "http://www.***********.com/myPage.asp";
-
string postData;
-
foreach (DataRow drow in datatable.Rows)
-
{
-
id = (int)drow[0];
-
field1 = drow[1].ToString();
-
field2 = drow[2].ToString();
-
Print(id.ToString(), 6);
-
Print(field1, 20);
-
Print(field2.ToString(), 6);
-
postData = "id=" + id.ToString();
-
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseURL);
-
req.Method = "POST";
-
ASCIIEncoding encoding = new ASCIIEncoding();
-
byte[] byte1 = encoding.GetBytes(postData);
-
req.ContentType="application/x-www-form-urlencoded";
-
req.ContentLength = postData.Length;
-
Stream newStream = req.GetRequestStream();
-
newStream.Write(byte1, 0, byte1.Length);
-
Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", req.ContentLength);
-
newStream.Close();
-
}
-
datatable = null;
-
sqldataadapter = null;
-
sqlcommand = null;
-
c.Close();
-
}
-
c = null;
-
Console.Read();
-
}
-
protected static void OnStateChanged(object sender, StateChangeEventArgs e)
-
{
-
Console.WriteLine(
-
"sql server state is -> {0}",
-
e.CurrentState.ToString("g")
-
);
-
}
-
protected static void OnInfoMessage(object sender, SqlInfoMessageEventArgs e)
-
{
-
foreach (SqlError err in e.Errors)
-
{
-
Console.WriteLine(err.Message);
-
}
-
}
-
static void Print(string towrite, int maxlen)
-
{
-
if (towrite.Length >= maxlen)
-
{
-
Console.Write(towrite.Substring(0, maxlen - 4) + "... ");
-
return;
-
}
-
towrite += new string(' ', maxlen - towrite.Length);
-
-
Console.Write(towrite);
-
}
-
}
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: Sagaert Johan |
last post by:
i get this error if i write this :
using System.Net.Sockets;
....
....
TcpClient tcp;
tcp=new TcpClient();
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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,...
| |