473,465 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Properly terminating connections

Hi!

I use following code to execute SP's on SQL server from my web page:
// Create Instance of Connection and Command Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand = new SqlCommand("spcGetItem",
myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC
SqlParameter parameterItemKey = new SqlParameter("@_iItemKey",
SqlDbType.Int, 4);
parameterItemKey.Value = iItemKey;
myCommand.Parameters.Add(parameterItemKey);
// Add OUT Parameters to SPROC
SqlParameter parameterRetVal = new SqlParameter("@_oRetVal",
SqlDbType.Int, 4);
parameterRetVal.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(parameterRetVal);
// Execute the command
myConnection.Open();
SqlDataReader result =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction);

Looks like connection get closed, but I looked into process info and can see
many connections open, however no user browsing site at the same time...

What is the sure way to close/terminate connection?

Nov 15 '05 #1
3 1806
Have you tried calling myConnection.Close() or
myConnection.Dispose()? How are you handling connection
pooling?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
Hi!

I use following code to execute SP's on SQL server from my web page: // Create Instance of Connection and Command Object SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings ["connectionString"]); SqlCommand myCommand = new SqlCommand ("spcGetItem",myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Add Parameters to SPROC
SqlParameter parameterItemKey = new SqlParameter("@_iItemKey",SqlDbType.Int, 4);
parameterItemKey.Value = iItemKey;
myCommand.Parameters.Add(parameterItemKey);
// Add OUT Parameters to SPROC
SqlParameter parameterRetVal = new SqlParameter("@_oRetVal",SqlDbType.Int, 4);
parameterRetVal.Direction = ParameterDirection.Output; myCommand.Parameters.Add(parameterRetVal);
// Execute the command
myConnection.Open();
SqlDataReader result =
myCommand.ExecuteReader(CommandBehavior.CloseConn ection);

Looks like connection get closed, but I looked into process info and can seemany connections open, however no user browsing site at the same time...
What is the sure way to close/terminate connection?

.

Nov 15 '05 #2
I don't know what you mean by "connection pooling"...

All I do is Open - get - close (???) every time I need data.
This is Web App and I do not keep connections open at all.

"Jerry Negrelli" <je************@nospam.datascientific.com> wrote in message
news:01****************************@phx.gbl...
Have you tried calling myConnection.Close() or
myConnection.Dispose()? How are you handling connection
pooling?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
Hi!

I use following code to execute SP's on SQL server from

my web page:
// Create Instance of Connection and Command

Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings

["connectionString"]);
SqlCommand myCommand = new SqlCommand

("spcGetItem",
myConnection);

// Mark the Command as a SPROC
myCommand.CommandType =

CommandType.StoredProcedure;

// Add Parameters to SPROC
SqlParameter parameterItemKey = new

SqlParameter("@_iItemKey",
SqlDbType.Int, 4);
parameterItemKey.Value = iItemKey;
myCommand.Parameters.Add(parameterItemKey);
// Add OUT Parameters to SPROC
SqlParameter parameterRetVal = new

SqlParameter("@_oRetVal",
SqlDbType.Int, 4);
parameterRetVal.Direction =

ParameterDirection.Output;
myCommand.Parameters.Add(parameterRetVal);
// Execute the command
myConnection.Open();
SqlDataReader result =
myCommand.ExecuteReader(CommandBehavior.CloseConn ection);

Looks like connection get closed, but I looked into

process info and can see
many connections open, however no user browsing site at

the same time...

What is the sure way to close/terminate connection?

.

Nov 15 '05 #3
SQL Server Connection Pooling is enabled by default & it
is definitely recommended, since any connection you
create with an identical connection string will just
reuse the same connection. If you really want the
connection to go away, you may be able to
add "Pooling=false" or something like that to your
connection string, but that syntax may not be exact.

This article may give you a bit more info:

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnmdac/html/pooling2.asp

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
-----Original Message-----
I don't know what you mean by "connection pooling"...

All I do is Open - get - close (???) every time I need data.This is Web App and I do not keep connections open at all.
"Jerry Negrelli" <je************@nospam.datascientific.com> wrote in
messagenews:01****************************@phx.gbl...
Have you tried calling myConnection.Close() or
myConnection.Dispose()? How are you handling connection pooling?

Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
>-----Original Message-----
>Hi!
>
>I use following code to execute SP's on SQL server from
my web page:
> // Create Instance of Connection and
Command Object
> SqlConnection myConnection = new
>SqlConnection(ConfigurationSettings.AppSettings

["connectionString"]);
> SqlCommand myCommand = new SqlCommand

("spcGetItem",
>myConnection);
>
> // Mark the Command as a SPROC
> myCommand.CommandType =

CommandType.StoredProcedure;
>
> // Add Parameters to SPROC
> SqlParameter parameterItemKey = new

SqlParameter("@_iItemKey",
>SqlDbType.Int, 4);
> parameterItemKey.Value = iItemKey;
> myCommand.Parameters.Add
(parameterItemKey); >
>
> // Add OUT Parameters to SPROC
> SqlParameter parameterRetVal = new

SqlParameter("@_oRetVal",
>SqlDbType.Int, 4);
> parameterRetVal.Direction =

ParameterDirection.Output;
> myCommand.Parameters.Add(parameterRetVal);
>
>
> // Execute the command
> myConnection.Open();
> SqlDataReader result =
>myCommand.ExecuteReader (CommandBehavior.CloseConnection); >
>Looks like connection get closed, but I looked into

process info and can see
>many connections open, however no user browsing site

at the same time...
>
>What is the sure way to close/terminate connection?
>
>
>
>
>
>.
>

.

Nov 15 '05 #4

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

Similar topics

3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
4
by: Angelos | last post by:
I get this error mysql_pconnect Too many connections ... every now and then. Does anyone knows where it comes from ? There are a lot of sites running on the server and all of them use the...
5
by: Xarky | last post by:
Hi, I am creating a windows form, and when a specified event occurs (button click), I am hiding the windows form and opening a new windows form. When opening the new windows form and closing...
17
by: Peter Proost | last post by:
Hi Group, I've got an interesting problem, I don't know if this is the right group but I think so because everything I've read about it so far says it's a .net problem. Here's the problem, we're...
3
by: Martin Arvidsson | last post by:
Hi! I am starting up a thread that is listening for tcp connections in the thread i am using while (true) { // Handle the tcp stuff!! }
17
by: geniajanssen | last post by:
Hi there: I cannot get the code below to work properly. It works fine on the first loop but the next times around "$querySQL = 'SELECT * FROM host_index'" returns the wrong value. Can somebody...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
23
by: SaraLeePerson | last post by:
Dear group, I am seeking a easy to maintain and more importantly *working* way to pre-fetch images, so the pages I develop load smoothly without seeing the images kick in flicker as they usually...
4
by: kessa | last post by:
Hi Guys, I've recently had a problem with my site displaying a "system resources exceeded" error message ... and whilst searching this site for a solution (which I think I've now found) I came...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.