difference between connection.close and command.connection.close

hello,

What is the difference between odbcconnection.close and odbccommand.connection.close?
I am making connection once in my application in global.asax and opening connection at application_start event and closing it at application_end event. I am accessing connection through "global.myconnection" in webforms.
NOw in the webforms,do I have to mycommand.connection.open before comand.executereader??
Does mycommand.connection.close , closes the odbcconnection that I make in gloabl.asax?
It is confusing, because on the first function executing on webform, when I mycommand.executereader it runs fine, then I mycommand.connection.close. In some other function on the same webform which executes later ,when I try to mycommand.executereader , it gives me error that connection state is close, even if I make another odbc command object. So I have to mycommand.connection.open in it.
However, if I mycommand.connection.open in the function which executes first, it gives me error that connection is already open.
Please explain this situation.
Thanks,
0
bilalso
3/13/2004 11:46:35 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

6 Replies
970 Views

Similar Articles

[PageSpeed] 4

The first is the object linked to your "odbcconnection" ie:


Dim vOdbcConnection As OdbcConnection = New OdbcConnection(.................)


The second is the connection used in your "odbccommand" object ie:

vOdbcCommand = New OdbcCommand(strSQL, vOdbcConnection)


This is very usefull is if have many connections.

0
me_titus
3/14/2004 12:48:45 AM
Do this:


##################GLOBAL.ASAX##################
sub Application_Start()
"When the first user come to your site"
----Open Database-----
end sub

sub Application_End()
"When the last user leaves your site"
----Close Database-----
end sub

##################STARTPAGE.ASAP##################
sub Form_Load()
----Make the Queries (object OdbcCommand)-----
end sub



I hope this helps you.
0
me_titus
3/14/2004 12:54:43 AM
Thanks for reply. 

But in all cases I have to make new queries all in different functions on a single webform.
Should I make a single odbc command at the top of webform??
Public Class login
Inherits System.Web.UI.Page
Public strsql As String
dim mycommand as new odbccommand(global.myconnection,strsql)
.................
and use the same command object throughout the webform by changing the mycommand.commandtext ??
If this is the case then should I mycommand.connection.open before mycommand.executereader and then mycommand.connection.close ?
or I just open and close mycommand.connection once...and keep changing the mycommand.commandtext ??
ALso, I should not myconnection.open and myconnection.close all the time..I need to do it once only in global.asax, rite ?
Thanks for the answers..helped me a great deal
0
bilalso
3/14/2004 1:11:16 AM
i really dont think that having a connection open all the time is a good solution.

But in any case, you should open the database(mycommand.connection.open), before using either mycommand.commandtext or odbccommand.

You dont need to create an instance of:
---dim mycommand as new odbccommand(global.myconnection,strsql)
in the beginning.
Create only the variable:
---Public vOdbcCommand As OdbcCommand
and then when you need it, create the instance of the object:
---vOdbcCommand = New OdbcCommand(strSQL, vOdbcConnection)

But the best options by far, is if you use an dataset(ADO.NET), or if you create an class, to handle with your database, with methods to open, close and to make queries to your database.
Then making imports of that class to your global.asax and yourpage.asp.net, to use its methods and properties.
You will have by far to write less code, and will make you code more legiable.
I Hpoe this helps.
0
me_titus
3/14/2004 1:30:07 AM
Thanks, I am trying it.
0
bilalso
3/14/2004 2:06:32 AM
If you nedd any help with it, just ask.

;)
0
me_titus
3/14/2004 2:57:39 AM
Reply:

Similar Artilces:

Connection.close() not closing my connection?
My servlet calls con.close() within the finally {} of a try..catch block. Yet I notice that sa_conn_info still lists the connection. Shouldn't the connection disappear from the sa_conn_info list when I close it? And if the answer to that is "yes, it should", has anybody seen situations like mine where it *doesn't* close it? Thanks for your help, Kathleen My bad... through a series of really stupid coding mistakes, I managed to cause a SQLException to be thrown from within the finally {} block before the connection could be closed... and I was ignoring the ...

underlying connection was closed: The connection was closed unexpectedly
Hi ,   I am working with wcf and linq  and i am facing a problem"The underlying connection was closed: The connection was closed unexpectedly. " when i am trying to return my linq query to the client.I tried for changing the code in web.config for client and server.like   Client :   <behaviors> <endpointBehaviors> <behavior name="debuggingBehaviour"> <dataContractSerializer maxItemsInObjectGraph="2147483646" />                 &nb...

SFtp connect
The following Ftp connect to a sftp site has the right port/usrname/password [verified thru filezilla], but when I try to connect via TIDFTP -- I get "Connection Closed Gracefully" upon ftp->Connect();; The ftp properties are below the code. I have no other Indy objects on the form. It ocurred to me that I may need something for sftp. ftp->Connect(); if (ftp->Connected()) { ::Sleep(1); } object ftp: TIdFTP AutoLogin = True Host = 'ftp.dailyaccess.com' Password ='XXXXX' Port = 21 Username = 'charles.leggette' ProxySet...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
  Hi I am using WebService in asp.net during webservices call an error occur some time. Which through the message like   The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept aliv...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server
Hi I am using WebService in asp.net during WebServices call an error occur some time. Which through the message like   The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was ...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Hi,  If anyone knows..... why would the above mentioned error occur?   It happens at this line of my code : iBranchHierarchyLevel = objdbAccess.org_GetBranchHierarchyLevel(iUserBranchID)   I am using a web reference - which is connected to objdbaccess and org_GetBranchHierarchyLevel is a method   tnx :) Follow this thread please http://forums.asp.net/t/1127234.aspx  Hosam Kamel Remember to click on Mark as answer on the post that helped you...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server
Hello everyone, Please I truly need your help. I just changed my code from asp.net 1.1 to 2.0, and my page calls both the database and webservice for data. In asp.net 1.1, my code works perfectly, but in 2.0, I keep getting this error "Exception Details: System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." I spent weeks online and I got this code, Public Class MyTestServiceInherits VHMS.SOAPService Protected Overrides Function GetWebRequest(ByVal uri As Uri) As System.Net.WebRequestDim we...

superreview granted: [Bug 338243] Enabling TLS for new IMAP connections doesn't close old connections : [Attachment 237619] close cached connections when socket type changes
Scott MacGregor <mscott@mozilla.org> has granted David Bienvenu <bienvenu@nventure.com>'s request for superreview: Bug 338243: Enabling TLS for new IMAP connections doesn't close old connections https://bugzilla.mozilla.org/show_bug.cgi?id=338243 Attachment 237619: close cached connections when socket type changes https://bugzilla.mozilla.org/attachment.cgi?id=237619&action=edit ...

superreview requested: [Bug 338243] Enabling TLS for new IMAP connections doesn't close old connections : [Attachment 237619] close cached connections when socket type changes
David Bienvenu <bienvenu@nventure.com> has asked Scott MacGregor <mscott@mozilla.org> for superreview: Bug 338243: Enabling TLS for new IMAP connections doesn't close old connections https://bugzilla.mozilla.org/show_bug.cgi?id=338243 Attachment 237619: close cached connections when socket type changes https://bugzilla.mozilla.org/attachment.cgi?id=237619&action=edit ...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. (SOMETIMES)
This is an Asp.net page that gets info from a IBM Shadow web system. This works 100% for getting HTML but when a image is added an error sometimes occurs. (Could it be the amount of data transfered???). The error is : "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." This ONLY happens in .net 2.0 and NEVER in .net 1.1. I have searched but not found an applicable solution for this. Is there a property that needs to be set different?   [CODE]HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sRemoteURL); /...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server #2
Hi I am using WebService in asp.net during webservices call an error occur some time. Which through the message like   The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. Description: An unha...

Error occure while calling a WCF Service.(The underlying connection was closed: The connection was closed unexpectedly.)
  Hi,I am using WCF service in my application. when i call a method in the service. i get the following error- System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly.Please Help!...

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. (Alternate requests)
Hi Experts,   I am experiencing the The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. for alternate SOAP requests. Can any one help me in this.   I made default proxy settings in config file so but no luck.. <system.net>      <defaultProxy>         <proxy usesystemdefault ="false"            proxyaddress = "http://proxyserver:80"     ...

Exception while calling .NET web service | System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Hi,   We have written a .NET web service which retrieves an xml file from the database. This web service is SSL secured and requires client certificates for connection.   Problem: The web service is throwing an exception while retrieving large files. It works fine when the file size is around 1 MB, but fails with a file size of around 65 MB with the following exception: System.InvalidOperationException: There is an error in XML document (1, 38455668). ---> System.IO.IOException: Unable to read data from the transport connection. ---> System.Net.Sockets.SocketException: ...

Web resources about - difference between connection.close and command.connection.close - asp.net.web-forms

Difference - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

3Q EARNINGS: Mark Zuckerberg on the Differences Between Messenger and WhatsApp
When Facebook announced its intent to acquire cross-platform messaging application WhatsApp in February, questions surfaced on whether WhatsApp ...

Facebook Tips: What’s the Difference between Top News and Most Recent?
The following is part of our series, Facebook Tips, which answers some of the most commonly asked questions about using Facebook. While we hope ...

The Floral Society opens a bar with a difference in Kingston
It's Canberra's newest bar but it's less drinks and more daisy.

iOS App Store brings in 75% more revenue than Play Store despite difference in downloads
... app store. The iOS App Store now earns 75 percent more revenue than the Google Play Store. This is an increase over the 70 percent difference ...

Sprint cuts customer service jobs, says customers won’t notice a difference
Sprint is reportedly cutting 2,500 jobs, including 2,000 in customer service, but the company told Ars that subscribers won't actually see any ...

"I see little difference between a drone hovering near my window, and someone standing across the street ...
"Both can peer into my office. But I may be in the minority here. When I mentioned it to my wife, she was outraged by the intrusion and briefly ...

The difference between billionaires and the rest of us - Business Insider Deutschland
A quote from the late Apple founder sheds light on the "billionaire mentality."

It’s Mardi Gras: Celebrate Both Creole & Cajun But Know The Difference
... was in a Sazerac cocktail and how tabasco peppers were harvested. Above all, the most enlightening topic for me was to learn the real differences ...

Preview: Making a Difference - 60 Minutes Videos - CBS News
On a special edition of "60 Minutes Presents," the news magazine takes a look at Americans from all walks of life who are making a difference. ...

Resources last updated: 2/3/2016 2:06:17 PM