Click here to Skip to main content
15,849,829 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Varad_Rajan24-Jan-08 1:23
Varad_Rajan24-Jan-08 1:23 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Gareth H24-Jan-08 1:30
Gareth H24-Jan-08 1:30 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Varad_Rajan24-Jan-08 1:32
Varad_Rajan24-Jan-08 1:32 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Varad_Rajan24-Jan-08 1:34
Varad_Rajan24-Jan-08 1:34 
GeneralRe: How to disable keydown event in Context Menu Strip ? Pin
Anthony Mushrow24-Jan-08 2:03
professionalAnthony Mushrow24-Jan-08 2:03 
QuestionHow to Change or Generate a file with Owner using .NET 1.1 Pin
Ninerocky24-Jan-08 0:29
Ninerocky24-Jan-08 0:29 
Questionhow to add .rpt and .cri extensions in IIS (windows 2000 with crystal reports 9 installed on the same) Pin
here2learn24-Jan-08 0:06
here2learn24-Jan-08 0:06 
GeneralSqlConnection and scope Pin
Dewald23-Jan-08 23:40
Dewald23-Jan-08 23:40 
Hi all,

I've been laboriously opening and closing SqlConnections, SqlCommands and SqlDataReaders etc. until I recently found out about the nice using approach to all of that.

using (SqlConnection mySqlConnection = new SqlConnection(...))
{
   mySqlConnection.Open();
   using (SqlCommand mySqlCommand = new SqlCommand(...))
   {
      using (SqlDataReader mySqlDataReader = mySqlCommand.Execute())
      {
      ...
      }
   }
}


One thing that I am unsure about though has to do with the scope of a SqlConnection if used this way.

Let's say for instance that I have two functions that perform an action against the database, myFunc1() and myFunc2(). Inside each of these functions the SqlCommand and SqlDataReader is implemented. If a connection is established as described above, it will not have scope inside such a function:

using (SqlConnection mySqlConnection = new SqlConnection(...))
{
   myFunc1();
   myFunc2();
}


On the other hand I don't want to open the SqlConnection first in each function. I've heard talk of "connection pooling" so it might not be a problem to do so but I don't know about that. If anyone would care to explain conection pooling I'd appreciate.

But basically, my question is. Is there an elegant way of making the SqlConnection available to other functions that will be called from inside the using block or would it be better to have a good old instantiation of a SqlConnection class at the top, open it manually and then close it manually again?

I suppose one solution would be to pass the SqlConnection as a parameter to the function that will be working on it but for some reason I don't like that.

I'm sure there's an industry-wide accepted norm for doing this type of thing. Throughout the application there are references to the database but you don't want to open and close the DB connection every time.
GeneralRe: SqlConnection and scope Pin
N a v a n e e t h24-Jan-08 0:03
N a v a n e e t h24-Jan-08 0:03 
QuestionCopy Contents in Excel Pin
mohankatari23-Jan-08 23:00
mohankatari23-Jan-08 23:00 
GeneralRe: Copy Contents in Excel Pin
Paul Conrad24-Jan-08 8:03
professionalPaul Conrad24-Jan-08 8:03 
Questionhow can i access the xml file in the in richtextbox in c#.net? Pin
samidhas23-Jan-08 22:01
samidhas23-Jan-08 22:01 
AnswerRe: how can i access the xml file in the in richtextbox in c#.net? Pin
N a v a n e e t h24-Jan-08 0:04
N a v a n e e t h24-Jan-08 0:04 
Generalstatus bar Pin
mahenputta23-Jan-08 21:11
mahenputta23-Jan-08 21:11 
GeneralRe: status bar Pin
DaveyM6924-Jan-08 1:58
professionalDaveyM6924-Jan-08 1:58 
GeneralRe: status bar Pin
mahenputta24-Jan-08 2:36
mahenputta24-Jan-08 2:36 
GeneralRe: status bar Pin
DaveyM6924-Jan-08 2:45
professionalDaveyM6924-Jan-08 2:45 
GeneralRe: status bar Pin
mahenputta24-Jan-08 2:51
mahenputta24-Jan-08 2:51 
QuestionHow to make an auto-update tool? Pin
hio7723-Jan-08 20:42
hio7723-Jan-08 20:42 
GeneralRe: How to make an auto-update tool? Pin
Giorgi Dalakishvili23-Jan-08 22:17
mentorGiorgi Dalakishvili23-Jan-08 22:17 
GeneralRe: How to make an auto-update tool? Pin
N a v a n e e t h24-Jan-08 0:05
N a v a n e e t h24-Jan-08 0:05 
Questionhow to save ? Pin
samidhas23-Jan-08 20:15
samidhas23-Jan-08 20:15 
GeneralRe: how to save ? Pin
N a v a n e e t h24-Jan-08 0:07
N a v a n e e t h24-Jan-08 0:07 
GeneralURL monitoring Pin
Adeel Chaudhry23-Jan-08 18:26
Adeel Chaudhry23-Jan-08 18:26 
GeneralRe: URL monitoring Pin
Paul Conrad23-Jan-08 18:53
professionalPaul Conrad23-Jan-08 18:53 

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.