Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
JokeRe: Sharpening the Saw [modified] Pin
AspDotNetDev1-Jun-11 10:37
protectorAspDotNetDev1-Jun-11 10:37 
GeneralRe: Sharpening the Saw Pin
SledgeHammer011-Jun-11 11:21
SledgeHammer011-Jun-11 11:21 
GeneralRe: Sharpening the Saw Pin
Pete O'Hanlon1-Jun-11 21:47
mvePete O'Hanlon1-Jun-11 21:47 
AnswerRe: Sharpening the Saw [modified] Pin
RobCroll1-Jun-11 14:11
RobCroll1-Jun-11 14:11 
QuestionI do not understand why the error ! :S Pin
ismail201-Jun-11 2:31
ismail201-Jun-11 2:31 
AnswerRe: I do not understand why the error ! :S Pin
PIEBALDconsult1-Jun-11 2:50
mvePIEBALDconsult1-Jun-11 2:50 
AnswerRe: I do not understand why the error ! :S Pin
Eddy Vluggen1-Jun-11 2:59
professionalEddy Vluggen1-Jun-11 2:59 
AnswerRe: I do not understand why the error ! :S Pin
Not Active1-Jun-11 2:59
mentorNot Active1-Jun-11 2:59 
Well as the error indicates the connection is still opened from a previous attempt or some other method.

Since you are not using any try/catch blocks the code could have failed at any point between the Open and Close calls thus leaving the connection open.

Make use of the using statement

using(SqlConnection conn = new SqlConnection("..."))
{
  using(SqlCommand cmd = new SqlCommand("...", conn))
  {
    // Do actions here
  }
}


With this the connection and command will be disposed of regardless of whether a failure has occurred.

You should learn to program defensively also.

if(conn.State != ConnectionState.Open)
  conn.Open();


And lastly, use parameterized queries rather than concatenate a string for the command.

I know the language. I've read a book. - _Madmatt
modified on Wednesday, June 1, 2011 9:34 AM

GeneralRe: I do not understand why the error ! :S Pin
ismail201-Jun-11 3:05
ismail201-Jun-11 3:05 
GeneralRe: I do not understand why the error ! :S Pin
Not Active1-Jun-11 3:21
mentorNot Active1-Jun-11 3:21 
GeneralRe: I do not understand why the error ! :S Pin
ismail201-Jun-11 3:29
ismail201-Jun-11 3:29 
GeneralRe: I do not understand why the error ! :S Pin
Not Active1-Jun-11 3:32
mentorNot Active1-Jun-11 3:32 
GeneralRe: I do not understand why the error ! :S Pin
ismail201-Jun-11 3:34
ismail201-Jun-11 3:34 
GeneralRe: I do not understand why the error ! :S Pin
Not Active1-Jun-11 3:38
mentorNot Active1-Jun-11 3:38 
GeneralRe: I do not understand why the error ! :S Pin
BobJanova1-Jun-11 4:12
BobJanova1-Jun-11 4:12 
AnswerRe: I do not understand why the error ! :S Pin
Pete O'Hanlon1-Jun-11 3:25
mvePete O'Hanlon1-Jun-11 3:25 
GeneralRe: I do not understand why the error ! :S Pin
ismail201-Jun-11 3:33
ismail201-Jun-11 3:33 
GeneralRe: I do not understand why the error ! :S Pin
Not Active1-Jun-11 3:37
mentorNot Active1-Jun-11 3:37 
GeneralRe: I do not understand why the error ! :S Pin
ismail201-Jun-11 3:44
ismail201-Jun-11 3:44 
GeneralRe: I do not understand why the error ! :S Pin
Pete O'Hanlon1-Jun-11 3:54
mvePete O'Hanlon1-Jun-11 3:54 
QuestionLogical issue with a recursive function call Pin
John-ph1-Jun-11 2:23
John-ph1-Jun-11 2:23 
AnswerRe: Logical issue with a recursive function call Pin
dasblinkenlight1-Jun-11 5:37
dasblinkenlight1-Jun-11 5:37 
QuestionMemory expensive rubber band selection? Pin
Chesnokov Yuriy31-May-11 23:10
professionalChesnokov Yuriy31-May-11 23:10 
AnswerRe: Memory expensive rubber band selection? Pin
BobJanova31-May-11 23:36
BobJanova31-May-11 23:36 
AnswerRe: Memory expensive rubber band selection? Pin
Chesnokov Yuriy1-Jun-11 0:42
professionalChesnokov Yuriy1-Jun-11 0:42 

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.