[英]An unhandled exception occurred during the execution of the current web request. ASP.NET
I just ran my program and I got this error message我刚刚运行了我的程序,但收到了此错误消息
An unhandled exception occurred during the execution of the current web request.
执行当前 Web 请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.
请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
with stack trace带堆栈跟踪
[NullReferenceException: Object reference not set to an instance of an object.]
OverseasCreditCard.Default.Page_Load(Object sender, EventArgs e) +667
System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177
I am using ASP.NET C#, does anyone know what happened?我正在使用 ASP.NET C#,有人知道发生了什么吗?
Incomplete information: we need to know which line is throwing the NullReferenceException in order to tell precisely where the problem lies.不完整的信息:我们需要知道哪一行抛出NullReferenceException才能准确判断问题出在哪里。
Obviously, you are using an uninitialized variable (ie, a variable that has been declared but not initialized) and try to access one of its non-static method/property/whatever.显然,您正在使用未初始化的变量(即,已声明但未初始化的变量)并尝试访问其非静态方法/属性/任何内容之一。
Solution : - Find the line that is throwing the exception from the exception details - In this line, check that every variable you are using has been correctly initialized (ie, it is not null)解决方案: - 从异常详细信息中找到引发异常的行 - 在这一行中,检查您使用的每个变量是否都已正确初始化(即,它不为空)
Good luck.祝你好运。
I had the same problem and found out that I had forgotten to include the script in the file which I want to include in the live site.我遇到了同样的问题,发现我忘记将脚本包含在我想包含在实时站点中的文件中。
Also, you should try this:另外,你应该试试这个:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
Here is the code with line 156, it has try and catch above it这是第 156 行的代码,它上面有 try and catch
/// <summary>
/// Execute a SQL Query statement, using the default SQL connection for the application
/// </summary>
/// <param name="query">SQL query to execute</param>
/// <returns>DataTable of results</returns>
public static DataTable Query(string query)
{
DataTable results = new DataTable();
string configConnectionString = "ApplicationServices";
System.Configuration.Configuration WebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.config");
System.Configuration.ConnectionStringSettings connString;
if (WebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
{
connString = WebConfig.ConnectionStrings.ConnectionStrings[configConnectionString];
if (connString != null)
{
try
{
using (SqlConnection conn = new SqlConnection(connString.ToString()))
using (SqlCommand cmd = new SqlCommand(query, conn))
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd))
dataAdapter.Fill(results);
return results;
}
catch (Exception ex)
{
throw new SqlException(string.Format("SqlException occurred during query execution: ", ex));
}
}
else
{
throw new SqlException(string.Format("Connection string for " + configConnectionString + "is null."));
}
}
else
{
throw new SqlException(string.Format("No connection strings found in Web.config file."));
}
}
Check your problem is solved.检查您的问题是否已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.