Problem with Connection.

  • Thread starter Thread starter Mahesh D. Rane
  • Start date Start date
M

Mahesh D. Rane

Hi,

I am connecting to sql databse from windows C# form.
when i close the form, then also the connection to databse
is active. Its not allowing me to delete the database.
But if i close the complete application, then databse is
delete successfully.
ANy solution ?

Regards,
Mahesh
 
Mahesh:

Can you post the code?

Two quick questions:

1) How do you know the connection is still open?
2) Are you explicitly opening and closing it?
 
Yes i am opening and closing the connection.

Code :


string strSalesCode = "";
SqlConnection myImageCon =
new SqlConnection(cConnImage);
myImageCon.Open();

SqlDataReader drReader;
string strQuery = "select
SalesCode from UserMaster where UserId=" + "'" +
cCommon.UserID.ToString() + "'";
SqlCommand myCmd = new
SqlCommand (strQuery, myImageCon) ;
drReader =
myCmd.ExecuteReader();

while(drReader.Read())
{
strSalesCode =
drReader["SalesCode"].ToString();
}


myImageCon.Close();
myCmd = null;
myImageCon = null;
 
I believe the connection pool keeps one connection open throughout the life
of the app once opened.
Yes i am opening and closing the connection.

Code :


string strSalesCode = "";
SqlConnection myImageCon =
new SqlConnection(cConnImage);
myImageCon.Open();

SqlDataReader drReader;
string strQuery = "select
SalesCode from UserMaster where UserId=" + "'" +
cCommon.UserID.ToString() + "'";
SqlCommand myCmd = new
SqlCommand (strQuery, myImageCon) ;
drReader =
myCmd.ExecuteReader();

while(drReader.Read())
{
strSalesCode =
drReader["SalesCode"].ToString();
}


myImageCon.Close();
myCmd = null;
myImageCon = null;
-----Original Message-----
Mahesh:

Can you post the code?

Two quick questions:

1) How do you know the connection is still open?
2) Are you explicitly opening and closing it?



.
 
A couple of things...

You should be sure to use

try
open
do stuff
catch
some bad happend
finally
close <-- Close() returns a connection to the connection pool.

Your connection pools can be managed using the Connection Lifetime,
Connection Reset, Pooling, Max Pool Size, and Min Pool Size connection
string modifiers.

Connection Lifetime controls how long before a connection should be
automatically destroyed and is useful in clustering and load balancing.

Pooling can be set to either True or False, and of course it specifies
whether connection pooling should be used in your application. It follows
that Max Pool Size and Min Pool Size control just how many connections
should be automatically created in a new pool and how many connections that
pool can hold.


William Ryan said:
I believe the connection pool keeps one connection open throughout the life
of the app once opened.
Yes i am opening and closing the connection.

Code :


string strSalesCode = "";
SqlConnection myImageCon =
new SqlConnection(cConnImage);
myImageCon.Open();

SqlDataReader drReader;
string strQuery = "select
SalesCode from UserMaster where UserId=" + "'" +
cCommon.UserID.ToString() + "'";
SqlCommand myCmd = new
SqlCommand (strQuery, myImageCon) ;
drReader =
myCmd.ExecuteReader();

while(drReader.Read())
{
strSalesCode =
drReader["SalesCode"].ToString();
}


myImageCon.Close();
myCmd = null;
myImageCon = null;
-----Original Message-----
Mahesh:

Can you post the code?

Two quick questions:

1) How do you know the connection is still open?
2) Are you explicitly opening and closing it?
Hi,

I am connecting to sql databse from windows C# form.
when i close the form, then also the connection to databse
is active. Its not allowing me to delete the database.
But if i close the complete application, then databse is
delete successfully.
ANy solution ?

Regards,
Mahesh


.
 
Back
Top