未处理的参数异常是错误 [英] Argument exception was unhandled is the error

查看:91
本文介绍了未处理的参数异常是错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望使用visual studio将SQL数据库连接到C#。执行时我收到错误



String source =有连接字符串

SqlConnection con = new SqlConnection(source);

{

}



我的尝试:



尝试所有可能的操作改变源字符串

wanted to connect the SQL database to C# using visual studio . When executed i'm getting an error

String source = "has the connection string "
SqlConnection con = new SqlConnection(source);
{
}

What I have tried:

tried all possible operations altering the source string

推荐答案

对于初学者,你需要查看异常本身 - 参数异常未处理不是错误,它告诉你发生了错误而你没有处理它。

所以放一个试试...... catch 阻止代码循环,并使用调试器查看错误的确切内容,包括任何InnerException数据。



它也值得仔细检查你的代码:该行通常不会抛出任何异常,它会在您打开实际连接之前检查连接字符串。



虽然值得检查您的连接字符串 - 这可能是他lp:简单的SQL连接字符串创建 [ ^ ]
For starters, you need to look at the exception itself - "Argument exception was unhandled" isn't the error, it's telling you that an error occurred and you didn't handle it.
So put a try ... catch block round the code, and use the debugger to look at exactly what the error is, including any InnerException data.

It's also worth double checking your code: that line doesn't normally throw any exceptions, it doesn't check the connection string until you Open the actual connection.

It's worth checking your connection string though - this may help: Simple SQL Connection String Creation[^]


这篇关于未处理的参数异常是错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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