sqlConnection / Befehl mit Anweisung + try / catch-Block [duplizieren]
Diese Frage hat hier bereits eine Antwort:
try / catch + using, rechte Syntax 7 answersWas ist ein korrekter Ansatz für try / catch inside using oder inside try / catch?
using (SqlConnection connection = CreateSqlConnection(connString))
{
using (SqlCommand command = CreateSqlCommand()
{
try{//open connection + execute command + do something else}
catch{//do something}
}
}
vs.
try
{
using (SqlConnection connection = CreateSqlConnection(connString))
{
using (SqlCommand command = CreateSqlCommand()
{
//open connection + execute command + do something else
}
}
}
catch
{
//do something
}