Click here to Skip to main content
15,894,955 members
Home / Discussions / C#
   

C#

 
GeneralRe: Gracefully shutting down threads Pin
CWIZO18-Jan-06 3:01
CWIZO18-Jan-06 3:01 
QuestionVS 2005 UK edition Pin
pieterman17-Jan-06 11:44
pieterman17-Jan-06 11:44 
AnswerRe: VS 2005 UK edition Pin
Christian Graus17-Jan-06 14:03
protectorChristian Graus17-Jan-06 14:03 
GeneralRe: VS 2005 UK edition Pin
pieterman18-Jan-06 7:03
pieterman18-Jan-06 7:03 
QuestionTry/Catch Variable Scoping Pin
RobertF5717-Jan-06 11:34
RobertF5717-Jan-06 11:34 
AnswerRe: Try/Catch Variable Scoping Pin
Guffa17-Jan-06 11:50
Guffa17-Jan-06 11:50 
GeneralRe: Try/Catch Variable Scoping Pin
RobertF5717-Jan-06 11:55
RobertF5717-Jan-06 11:55 
AnswerRe: Try/Catch Variable Scoping Pin
Guffa17-Jan-06 12:14
Guffa17-Jan-06 12:14 
Just don't let the code panic. Just because a database call failed, you don't need to drop everything and run. In the catch section just set the rdr variable to null and prepare the error message, then after the try--catch block you just check if the variable is null or not. If it's not null, loop thought the data. If it's null, just skip that part and go directly on to gracefully closing the database.

I always put the connection object in a using() block. That way, what ever happens, at least the database connection is closed correctly.

using (SqlConnection connection = new SqlConnection(...)) {<br />
...do the database stuff<br />
}


The using() block always calls the Dispose method of the connection, and as the Dispose method of the connection always calls the Close method, you don't have to do that either.

---
b { font-weight: normal; }

GeneralRe: Try/Catch Variable Scoping Pin
RobertF5717-Jan-06 12:38
RobertF5717-Jan-06 12:38 
QuestionSetup Project - Getting the user selected install directory Pin
dotnetprgrmmr17-Jan-06 11:28
dotnetprgrmmr17-Jan-06 11:28 
AnswerRe: Setup Project - Getting the user selected install directory Pin
Sasuko17-Jan-06 11:48
Sasuko17-Jan-06 11:48 
GeneralRe: Setup Project - Getting the user selected install directory Pin
dotnetprgrmmr17-Jan-06 12:00
dotnetprgrmmr17-Jan-06 12:00 
GeneralRe: Setup Project - Getting the user selected install directory Pin
Sasuko17-Jan-06 12:42
Sasuko17-Jan-06 12:42 
GeneralRe: Setup Project - Getting the user selected install directory Pin
dotnetprgrmmr18-Jan-06 6:09
dotnetprgrmmr18-Jan-06 6:09 
QuestionDatabase VS direct update Pin
Sasuko17-Jan-06 11:19
Sasuko17-Jan-06 11:19 
AnswerRe: Database VS direct update Pin
Guffa17-Jan-06 11:54
Guffa17-Jan-06 11:54 
GeneralRe: Database VS direct update Pin
Sasuko17-Jan-06 12:14
Sasuko17-Jan-06 12:14 
GeneralRe: Database VS direct update Pin
Dave Kreskowiak17-Jan-06 17:25
mveDave Kreskowiak17-Jan-06 17:25 
AnswerRe: Database VS direct update Pin
Guffa19-Jan-06 23:03
Guffa19-Jan-06 23:03 
QuestionMaking the panel invisible?? Pin
VPMahank17-Jan-06 11:12
VPMahank17-Jan-06 11:12 
AnswerRe: Making the panel invisible?? Pin
CWIZO17-Jan-06 21:11
CWIZO17-Jan-06 21:11 
GeneralRe: Making the panel invisible?? Pin
VPMahank18-Jan-06 1:32
VPMahank18-Jan-06 1:32 
QuestionHow can an NT Service cause itself to stop? Pin
dotnetprgrmmr17-Jan-06 11:12
dotnetprgrmmr17-Jan-06 11:12 
Questionfloating toolbar in C# Pin
jerryyag17-Jan-06 11:00
jerryyag17-Jan-06 11:00 
AnswerRe: floating toolbar in C# Pin
Sasuko17-Jan-06 11:44
Sasuko17-Jan-06 11:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.