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:
Anyone can tell me where I have gone wrong?
Thank you
原文:https://stackoverflow.com/questions/8239239
最满意答案
最佳测试:
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 inunpack
'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 ...
-
在Perl的帮助下更改文本(changing text with help of Perl)[2021-10-25]
这应该取消注释并在结尾添加$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); ...