I am trying to get my handler.ashx page working on our new AWS Windows Instance, I have installed IIS and seemingly everything i need for the handler to work on the instance, but when I pass a value to the handler and it tried to connect to our MSSQL DB, I get this exception thrown.
System.ComponentModel.Win32Exception (0x80004005): The network path was not found
I am not sure what could be going wrong, I checked everywhere online and most posts had to do with an incorrect connection string, however I am 100% positive my connection string is correct as I had this same handler working on my personal server hosted on hostbuddy. I also have the handler running perfectly on my localhost.
Handler Code:
<%@ WebHandler Language="C#" Class="PassHandler" %>
using System;
using System.Web;
using System.Data.SqlClient;
public class PassHandler : IHttpHandler
{
//www.mammothvr.com/PASSHandler/PassHandler.ashx?Key=
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//GET from UE4 PASS
if (context.Request.HttpMethod.ToString() == "GET")
{
//context.Response.Write("You sent a post!");
//get key from UE4
string KeyFromUE4 = context.Request.QueryString["Key"];
if (KeyFromUE4 == null)
{
context.Response.Write("ITS WORKING WITHOUT DB CONNECTION");
return;
}
//variables for later use
bool Validated = false;
int timetrial = 0;
int TrialDays = 0;
string temp = "";
//create reader obj
SqlDataReader rdr = null;
//create a connection object
SqlConnection conn = new SqlConnection(@"DeletedConnectionStringForThisPost");
conn.Close();
//create a command object
SqlCommand cmd = new SqlCommand("select * from PASSDBKEYS.dbo.Keys", conn);
try
{
// open the connection
conn.Open();
temp += " opened the connection";
// 1. get an instance of the SqlDataReader
rdr = cmd.ExecuteReader();
temp += " executed reader";
//while connection is reading rows
while (rdr.Read())
{
// get the results of each column
string Key = (string)rdr["PassKey"];
bool used = (bool)rdr["Used"];
bool Valid = (bool)rdr["Valid"];
bool IsTrial = (bool)rdr["IsTrialKey"];
temp += Key;
//check to see if key is used and if it is valid
if (Key == KeyFromUE4)
{
if (Valid == true)
{
if (IsTrial == true)
{
//check time left on trial
TrialDays = Convert.ToInt32(rdr["TrialDays"]);
DateTime DateActivated = (DateTime)rdr["DateActivated"];
timetrial = DateTime.Now.DayOfYear - DateActivated.DayOfYear;
if (TrialDays < timetrial) //if time is up on trial, set not valid anymore
{
Validated = false;
rdr.Close();
//new SqlCommand(" UPDATE Account SET name = Aleesha, CID = 24 Where name =Areeba and CID =11 )";
SqlCommand CMD = new SqlCommand("Update PASSDBKEYS.dbo.Keys SET Valid = 0 WHERE PassKey = @PassKey;", conn);
CMD.Parameters.Add(new SqlParameter("@PassKey", KeyFromUE4));
CMD.ExecuteNonQuery();
break;
}
}
else //not a trial account
{
Validated = true;
break;
}
}
else //key not valid anymore
{
Validated = false;
}
}
else if (Key != KeyFromUE4) //not a valid key
{
Validated = false;
}
}
}
//catch exception
catch (SqlException ex)
{
temp += ex.InnerException;
//rdr.Close();
conn.Close();
}
finally
{
//close the reader if it is done rading
if (rdr != null)
{
//close the reader
rdr.Close();
conn.Close();
}
else
{
//rdr.Close();
conn.Close();
}
}
//Send message back to UE4
if (Validated == true)
{
context.Response.Write("1");
}
else
{
context.Response.Write("Tried to read" +temp);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
If I just run the handler on AWS Instance, without a key parameter, All is good due to the fact that I don't connect to my db in that case, however when I pass a parameter is when I get the error (Because only then is the script supposed to connect to the db)
Any help would be amazing, I'm slowly starting to lose my mind over here, been at it for hours to no avail.
Figured it out, I had to change the incoming settings for IP's allowed to access the db.
If anyone else is having this problem in the future, check your db instances incoming port and IP settings!!!