首页 \ 问答 \ Catch System.Data.SqlClient.SqlException错误(Catch System.Data.SqlClient.SqlException error)

Catch System.Data.SqlClient.SqlException错误(Catch System.Data.SqlClient.SqlException error)

当我尝试访问我的ASP.NET Web应用程序上没有任何网络连接的网页时,我遇到了异常System.Data.SqlClient.SqlException

我试图通过使用try catch来捕获异常,但它不起作用。 以下是我的代码段:

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        SqlDataSource1.SelectCommand = "SELECT * FROM [UserDB]";
        SqlDataSource1.DataBind();
    }
    catch (SqlException ex)
    {
        Response.Redirect("/App/ErrorPage.aspx");
    }
}

我的try catch工作在我的网页本身的其他功能上。 例如,如果用户在未连接到网络时尝试删除记录,则会显示ErrorPage。 但是对于pageload方法,try catch没有按预期工作,错误显示为下面的网页: 在此处输入图像描述

谁能告诉我哪里出错了?

谢谢


I have met the exception System.Data.SqlClient.SqlException when I tried to access a webpage on my ASP.NET web application without any network connection.

I have tried to catch the exception by using a try catch, however it does not work. Below is my code snippet:

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        SqlDataSource1.SelectCommand = "SELECT * FROM [UserDB]";
        SqlDataSource1.DataBind();
    }
    catch (SqlException ex)
    {
        Response.Redirect("/App/ErrorPage.aspx");
    }
}

My try catch worked on other functions within my webpage itself. E.g. ErrorPage will be shown if user try to delete record when not connected to network. But as for the pageload method, the try catch did not work as expected, and the error showed as the webpage below: enter image description here

Anyone can tell me where I have gone wrong?

Thank you


原文:https://stackoverflow.com/questions/8239239
更新时间:2024-02-12 06:02

最满意答案

最佳测试:

use integer;
my $la = length($a);
my $r = $la % 8;
my @a = unpack(($r?"a$r":"")."(a8)".($la/8), $a);

似乎没有更有效的方法来做到这一点。

说明:

use integer; 是这样的($la/8)被截断为整数。 int($la/8)会做同样的事情。

$r是“余数”,是将其“分割”成8个块后剩余字符串的数量。

如果字符串可被8整除( $r==0 ),则unpack的模板中不能包含“余数”部分,否则"a$r" :( ($r?"a$r":"")

unpack模板的“商”或分块是: "(a8)".($la/8)

最后一行可以替换为以下代码,以获得更清晰的代码,代价是更多变量:

my $q = $la / 8;
my $tr = $r ? "a$r" : "";
my @a = unpack "$tr(a8)$q", $a;

Best by test:

use integer;
my $la = length($a);
my $r = $la % 8;
my @a = unpack(($r?"a$r":"")."(a8)".($la/8), $a);

There seems no cleaner way to do this efficiently.

Explanation:

use integer; is so that ($la/8) is truncated to integer. int($la/8) would do the same thing.

$r is the "remainder", the amount of remaining string after "dividing" it into chunks of 8.

If the string is evenly divisible by 8 ($r==0) there must be no "remainder" part included in unpack's template, otherwise "a$r": ($r?"a$r":"")

The "quotient", or chunking, part of unpack's template is: "(a8)".($la/8)

The last line can be replaced with the following for cleaner-looking code, at the cost of a couple more variables:

my $q = $la / 8;
my $tr = $r ? "a$r" : "";
my @a = unpack "$tr(a8)$q", $a;

相关问答

更多
  • 从输出中,您可以看到Makefile正在执行的命令。 这个: C:\Dwimperl\perl\bin\perl.exe file2c.pl -c 30000 par.exe C:\Dwimperl\perl\bin\perl514.dll C:\Dwimperl\perl\bin\libgcc_s_sjlj-1.dll C:\Program Files (x86)\GNU\GnuPG\pub\libstdc++-6.dll > boot_embedded_files.c 似乎试图传递此文件名: C:\P ...
  • 要获得与第一个代码段相同的行为,您需要将chunk_type作为binary读取。 更换 chunk_type :: size(32), 同 chunk_type :: binary-size(4), ( 4因为binary需要以字节为单位的大小,而不是位。) To get the same behavior as the first snippet, you need to read chunk_type as a binary. Replace chunk_type :: size(32), wi ...
  • 您的编辑器将该文件视为UTF-8,因此显示 my $subject = "Änderungen"; Perl有效地将文件视为iso-8859-1,因此它看到了 my $subject = "Ã?nderungen"; 告诉Perl你通过添加使用UTF-8编码你的脚本 use utf8; Your editor treats the file as UTF-8, so it shows my $subject = "Änderungen"; Perl effectively treats the fi ...
  • 最佳测试: use integer; my $la = length($a); my $r = $la % 8; my @a = unpack(($r?"a$r":"")."(a8)".($la/8), $a); 似乎没有更有效的方法来做到这一点。 说明: use integer; 是这样的($la/8)被截断为整数。 int($la/8)会做同样的事情。 $r是“余数”,是将其“分割”成8个块后剩余字符串的数量。 如果字符串可被8整除( $r==0 ),则unpack的模板中不能包含“余数”部分,否则" ...
  • Perl哈希使用一种称为桶链的技术。 具有相同散列的所有键(参见PERL_HASH_INTERNAL中的宏hv.h )都在同一个“桶”中,即一个线性列表。 根据perldata文档 如果在标量上下文中评估散列,则在散列为空时返回false。 如果有任何键/值对,则返回true; 更准确地说,返回的值是一个字符串,由使用的桶数和分配的桶数组成,用斜杠分隔。 这非常有用,只是为了找出Perl的内部哈希算法是否在您的数据集上表现不佳。 例如,你在哈希中粘贴10,000个东西,但在标量上下文中评估%HASH显示"1 ...
  • 这将满足您的需求。 我相信这个机制很清楚。 如果您需要进一步说明,请再次询问。 use strict; use warnings; my @array1 = qw( aaa bbb ccc eee eee ); my @array2 = qw( aaa aaa bbb ccc ccc ddd fff ); my %data; $data{$_}[0]++ for @array1; $data{$_}[1]++ for @array2; my ($add, $del, $upd) = (0, 0, 0 ...
  • 这应该取消注释并在结尾添加$suffix : my $suffix = 'abс hhhh dddd ccccc'; $string =~ s{#(blah bla blah)}{$1 $suffix}g; 更多信息是perldoc perlre和perldoc perlretut 。 This should uncomment and add $suffix to the end: my $suffix = 'abс hhhh dddd ccccc'; $string =~ s{#(blah bla b ...
  • 请看下面的例子: 第4章 。 他们介绍了PdfPTable的概念。 而不是创建像这样的"789456|Test" Chunk对象,然后不可能让这些Chunk的内容的各个部分正确对齐,你会发现用2列创建一个简单的PdfPTable要容易得多,添加"789456|" 和"Test"作为无边界细胞的内容。 所有其他解决方法将不可避免地导致代码更复杂且容易出错。 卡尔安德森提供的答案要复杂得多; Manish Sharma提供的答案是错误的。 虽然我不知道C#,但我试图写一个例子(基于我将如何在Java中实现这一点 ...
  • 你想在那条push线上做什么? 它包含表达式$i++ ,它将$1的值$1 ,因此while循环的每次迭代都会跳过文件中的另一行。 你的意思是$i + 1吗? What are you trying to do in that push line? It includes the expression $i++, which adds 1 to the value of $1, so each iteration of that while loop will be jumping down another ...
  • 你的函数返回对引用数组[[...],[...]]的引用,但你把它当作直接数组的引用([...],[...]) 。 最简单的解决方案是让函数返回一个数组数组。 以下内容还通过将参数分配给命名变量,使您的代码更加自我记录: sub gen{ my ($max_cols, $max_rows, $max_val) = @_; my $cols = 1 + int rand($max_cols - 1); my $rows = 1 + int rand($max_rows - 1); ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)