System.ComponentModel.Win32Exception(0x80004005)AWS VM IIS

时间:2018-02-05 20:13:20

标签: .net amazon-web-services iis ashx win32exception

我正在尝试让我的handler.ashx页面在新的AWS Windows实例上运行,我已经安装了IIS,看起来我需要处理器来处理实例,但是当我将值传递给处理程序时它试图连接到我们的MSSQL DB,我得到了这个异常。

  

System.ComponentModel.Win32Exception(0x80004005):网络路径   没找到

我不确定会出现什么问题,我在网上到处检查并且大多数帖子都与错误的连接字符串有关,但是我100%肯定我的连接字符串是正确的因为我有同样的处理程序工作在我的个人在hostbuddy上托管的服务器。我的处理程序也完全在我的localhost上运行。

处理程序代码:

<%@ 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 Instance上运行处理程序,没有关键参数,那么All是好的,因为在这种情况下我没有连接到我的数据库,但是当我传递参数时错误(因为只有这样才能将脚本连接到数据库)

任何帮助都会令人惊叹,我慢慢开始在这里失去理智,几个小时都无济于事。

1 个答案:

答案 0 :(得分:0)

想出来,我不得不改变允许访问数据库的IP的传入设置。

如果将来有其他人遇到此问题,请检查您的数据库实例传入端口和IP设置!!!

相关问题