System.ComponentModel.Win32Exception (0x80004005) AWS VM IIS
System.ComponentModel.Win32Exception (0x80004005) AWS VM IIS
我正在尝试让我的 handler.ashx 页面在我们的新 AWS Windows 实例上运行,我已经安装了 IIS 以及处理程序在该实例上运行所需的一切,但是当我向处理程序传递一个值,它尝试连接到我们的 MSSQL 数据库,我抛出了这个异常。
System.ComponentModel.Win32Exception (0x80004005): The network path
was not found
我不确定会出现什么问题,我在网上到处查了一下,大多数帖子都与不正确的连接字符串有关,但是我 100% 肯定我的连接字符串是正确的,因为我使用的是同一个处理程序我的个人服务器托管在 hostbuddy 上。我的本地主机上也有处理程序 运行ning。
处理程序代码:
<%@ 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;
}
}
}
如果我只是 运行 AWS 实例上的处理程序,没有关键参数,一切都很好,因为在这种情况下我没有连接到我的数据库,但是当我传递参数时是我收到错误的时候(因为只有那时脚本才应该连接到数据库)
任何帮助都会很棒,我在这里慢慢开始失去理智,已经花了几个小时无济于事。
弄清楚了,我不得不更改允许访问数据库的 IP 的传入设置。
如果以后有人遇到这个问题,请检查您的数据库实例传入端口和 IP 设置!!!
我正在尝试让我的 handler.ashx 页面在我们的新 AWS Windows 实例上运行,我已经安装了 IIS 以及处理程序在该实例上运行所需的一切,但是当我向处理程序传递一个值,它尝试连接到我们的 MSSQL 数据库,我抛出了这个异常。
System.ComponentModel.Win32Exception (0x80004005): The network path was not found
我不确定会出现什么问题,我在网上到处查了一下,大多数帖子都与不正确的连接字符串有关,但是我 100% 肯定我的连接字符串是正确的,因为我使用的是同一个处理程序我的个人服务器托管在 hostbuddy 上。我的本地主机上也有处理程序 运行ning。
处理程序代码:
<%@ 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;
}
}
}
如果我只是 运行 AWS 实例上的处理程序,没有关键参数,一切都很好,因为在这种情况下我没有连接到我的数据库,但是当我传递参数时是我收到错误的时候(因为只有那时脚本才应该连接到数据库)
任何帮助都会很棒,我在这里慢慢开始失去理智,已经花了几个小时无济于事。
弄清楚了,我不得不更改允许访问数据库的 IP 的传入设置。
如果以后有人遇到这个问题,请检查您的数据库实例传入端口和 IP 设置!!!