[已解决]如何获取在mysql中执行命令期间发生的所有错误 [英] [Solved] How to get all the errors occured during a command executed in mysql

查看:122
本文介绍了[已解决]如何获取在mysql中执行命令期间发生的所有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用来自asp.net C#的某些命令时,我想显示mysql显示的错误或警告.
例如:当我使用插入命令时,任何警告(例如数据在结尾处被截断)或错误(列超出范围)都将被存储在表中,或者我可以直接从asp.net&中访问.然后显示给用户.

实际上我有一个csv文件&我尝试从该文件导入数据(LOAD DATA)到mysql.因此,无论发生什么错误,我都希望将其显示给用户.
或类似的东西..

谁能帮忙!!

感谢Ankur 4 ur的回复..但是有一些MySQL的错误未在asp.net中定义.因此,它仅显示致命错误".那就是为什么我期望mysql错误列表.无论如何,我想我没有正确提到,所以你不能得到我想要的..

现在,我正在做什么,就是通过执行来自asp.net&的批处理文件从Windows命令提示符访问mysql命令提示符.然后将输出(例如插入5行或任何错误)重定向到txt文件.

I want to show errors or waring displayed by mysql while i use some command from asp.net C#.
For eg: When i use insert command, whatever warning(like data is Truncated at end) or errors(column is out of range) to be stored in a table or that i can directly access from asp.net & then display to user.

Actually i have a csv file & i try to import data (LOAD DATA) from this file to mysql. So,whatever error occurs i want to diplay those to user.
Or something similar..

Can anybody help!!

Thanks Ankur 4 ur reply.. But there are some error of mysql that are not defined in asp.net. so, it only shows "fatal error". That why i was expecting mysql error list. Anyways, i think i have not mentioned that correctly, so u cant get what i want..

Now what im doing is accessing mysql command prompt from windows command prompt by executing a batch file from asp.net & then redirect output (like 5 row inserted. or any error) to a txt file.

推荐答案

使用try-catch块捕获错误.
Use try-catch block to catch the error.
try
{
    //code for database operation goes here
}
catch(Exception ex)
{
    //write message to log (or display if you want). ex.Message contains the error string.

}


这篇关于[已解决]如何获取在mysql中执行命令期间发生的所有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆