473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SqlConnection, SqlCommand


I'm trying to understand SqlConnection(), SqlCommand()

For example. I use SqlConnection() as a parameter when I create a new
SqlCommand. Then I open SqlConnection(), then I execute the SqlCommand().
At that point I cannot use SqlConnection() again. Unless I .Close() it and
then .Open it right?

Then what is 'connection pooling' ?

Can't I run multiple SqlCommand()s on the same SqlConnection() somehow ?
--
incognito @ http://kentpsychedelic.blogspot.com/
Nov 16 '05 #1
1 1886
Now there are couple of things here

1) If you open a SqlConnection then you CAN execute multiple different SqlCommand.ExecuteNonQuery and SqlCommand.ExecuteScalar methods.
2) If you open a SqlConnection then you can execute only ONE SqlCommand.ExecuteReader. This is because, unlike the previous methods, Execute reader keeps the data live and hence the connection to the prticular table also is live so only one of them can execute untill you close the SqlConnection or close the SqlDataReader.
3) Connection Pooling is a different conecpt. Creating managed connections to the database are expensive. Hence when Connection Pooling is enabled, and you call Close on the SqlConnection object, although the SqlConnection object is closed, the underlying connection to the database is not closed, but its returned to the pool. When another request for a new connection comes in it utilizes the connection from the pool. This way the cost of creating and deleting connections to the database is saved.

--
Regards,
Saurabh Nandu
AksTech Solutions, reflecting your needs...
[ www.AksTech.com ]
[ www.MasterCSharp.com ]

"Donnie Darko" wrote:

I'm trying to understand SqlConnection(), SqlCommand()

For example. I use SqlConnection() as a parameter when I create a new
SqlCommand. Then I open SqlConnection(), then I execute the SqlCommand().
At that point I cannot use SqlConnection() again. Unless I .Close() it and
then .Open it right?

Then what is 'connection pooling' ?

Can't I run multiple SqlCommand()s on the same SqlConnection() somehow ?
--
incognito @ http://kentpsychedelic.blogspot.com/

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Donnie Darko | last post by:
I'm trying to understand SqlConnection(), SqlCommand() For example. I use SqlConnection() as a parameter when I create a new SqlCommand. Then I open SqlConnection(), then I execute the...
1
by: huzz | last post by:
I have a method that gets sqldatareader as shown below.. my question is how do i close the sqlconnection (objConn) object within this method? If i put the objconn.Close(); after the return then i...
3
by: sck10 | last post by:
Hello, I have a stored procedure that requires 3 parameters. How do you add multiple parameters for a SqlConnection? Thanks, Steven Public strConn = "Data Source=MyServer;Initial...
2
by: StephenRichter | last post by:
I have SqlServer loaded on my w2k system. The freeby I just downloaded from MS. Within WebMatrix I created a database. called it "WebMatrix" In WebMatrix I connect to the database. server:...
2
by: Nils Magnus Englund | last post by:
Hi, I've made a HttpModule which deals with user authentication. On the first request in a users session, it fetches data from a SQL Server using the following code: using (SqlConnection...
3
by: Jason Huang | last post by:
Hi, In C#.Net, can we have more than one SqlCommand in a SqlConnection? And in one SqlCommand, can we have more than one SqlDataReader in a SqlCommand? In what situation should I use...
1
by: John Bailo | last post by:
using ( SqlCommand cmd = new SqlCommand("select * sample"), new SqlConnection( sqlDsn ) ) ) { SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable();...
8
by: JoeW | last post by:
I normally use SqlConnection, SqlDataReader, SqlCommand for most of my queries but recently a friend of mine who is a long time java programmer suggested I use the IDbConnection, IDbCommand...
2
by: cj | last post by:
MySQLConnection.connectiontimeout() returns 15. I want to drop that to 3, but it is read only. I see you can include the timeout "Connection Timeout=30" as part of the connection string but I...
2
by: shauncl | last post by:
Hello Everyone, I'm currently writing a simple Windows Service (C#) that pings an ip address and inserts the pingreply result in a SQL table. I'm able to send a ping request and get the reply...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.