Masaia
asked on
OdbcConnection.Close triggers Global.asax Application_End?!?!?
In my programming I've got a connection to a SQL Server DataBase, but somehow my Session and Application variables got lost. Eventually I narrowed the problem down to three lines of coding, and later to one line of coding. At the end I came to the conclusion that 'somehow my OdbcConnection.Close() triggers the Application_End event after about 70 seconds.'
When I use the OdbcConnection.ReleaseObje ctPool() after the OdbcConnection.Close(), the Application_End is triggered right away. When I do a System.Threading.Thread.Sl eep() before the OdbcConnection.ReleaseObje ctPool() the Application_End is triggered after the number of seconds specifiied in the Sleep().
The strange part is, I also set my programming up to use a MySQL database. When I change my connection string to this database, the problem does NOT occur.
The problem can be 'activated' by one little line of coding:
OdbcConnection.Close()
So, I'm kind of assuming it's not a coding problem.
If I leave out the Close(), the problem also does NOT occur, but than (ofcourse) the number of connections to the database pile up. Which, definately isn't what I want either.
By now, I'm starting to thing it has to do with connection pooling, but I still have not figured out where exactly I could solve the problem, or 'monitor' something to see what is happening to the pool. Or some other statistics which might bring me closer to a solution.
I hope you can help me out, I've got the feeling I've already downloaded half the internet by now, looking for an answer, but still... No clue! I'm getting a bit frustrated by now, specially since all the rest is working fine on MySQL.
When I use the OdbcConnection.ReleaseObje
The strange part is, I also set my programming up to use a MySQL database. When I change my connection string to this database, the problem does NOT occur.
The problem can be 'activated' by one little line of coding:
OdbcConnection.Close()
So, I'm kind of assuming it's not a coding problem.
If I leave out the Close(), the problem also does NOT occur, but than (ofcourse) the number of connections to the database pile up. Which, definately isn't what I want either.
By now, I'm starting to thing it has to do with connection pooling, but I still have not figured out where exactly I could solve the problem, or 'monitor' something to see what is happening to the pool. Or some other statistics which might bring me closer to a solution.
I hope you can help me out, I've got the feeling I've already downloaded half the internet by now, looking for an answer, but still... No clue! I'm getting a bit frustrated by now, specially since all the rest is working fine on MySQL.
ASKER
Hey Patrikt, thanks for your quick response.
I use the following connection string, both OdbcConnections for my connection to the database(s).
SQL Server:
"Driver={SQL Native Client};Server=(local)\SQL Express;Da tabase=MyD B;Uid=MyUI D;Pwd=MyPW D;"
MySQL:
"Provider=MSDASQL;DRIVER={ MySQL ODBC 3.51 Driver};SERVER=localhost;D ATABASE=My DB;UID=MyU ID;PASSWOR D=MyPWD;OP TION=3"
I use ODBC because I don't use special coding (or SQL statements) for SQL or MySQL. Maybe a bit dumb of me, but my programming works for both databases without having to code differently... All I do to change databases is change my Application("Conn") variable. The only problem is: The SQL Server version stops doing what I want after 70 second aka when the Application_End is somehow triggered aka when my Session and Application variables are gone.
I'm currently building (another, I already did but now noted I was a bit stupid in that one) test web application to see what happens if I only use the connection string of SQL Server (directly) and set one Session-variable. If it crashes after about 70 seconds, I think I'm going to start to look for another line of work because I surely don't understand. (On the otherhand, it is consistently the same thing happening, there must be a solution...)
I use the following connection string, both OdbcConnections for my connection to the database(s).
SQL Server:
"Driver={SQL Native Client};Server=(local)\SQL
MySQL:
"Provider=MSDASQL;DRIVER={
I use ODBC because I don't use special coding (or SQL statements) for SQL or MySQL. Maybe a bit dumb of me, but my programming works for both databases without having to code differently... All I do to change databases is change my Application("Conn") variable. The only problem is: The SQL Server version stops doing what I want after 70 second aka when the Application_End is somehow triggered aka when my Session and Application variables are gone.
I'm currently building (another, I already did but now noted I was a bit stupid in that one) test web application to see what happens if I only use the connection string of SQL Server (directly) and set one Session-variable. If it crashes after about 70 seconds, I think I'm going to start to look for another line of work because I surely don't understand. (On the otherhand, it is consistently the same thing happening, there must be a solution...)
OK. If you create some small test application which will simulate the problem, send it to me (patrikt@volny.cz) and I test it there for you. It is sometimes good to try in completely different environment.
And be in peace, it is completely normal. I sometimes found that my work is composed only from suc "ghost" problems :)
Patrik
And be in peace, it is completely normal. I sometimes found that my work is composed only from suc "ghost" problems :)
Patrik
ASKER
Okay, so I built a test app. and... Ofcourse now the problem doesn't occur. So, it must be something in my coding in combination with SQL server. Now the question is, HOW do I make it so that you can see it... (It's pretty complex)
In the coding of Page_Load(), if I comment out ALL except for the DoConnOpen(...) and the DoConnClose(...) it STILL goes into the Application_End.
I also checked out the web.configs of my Test and 'official' programming, but I don't see any difference there... Sigh... Not getting closer yet.
P.S. Patrikt (why the extra t)... I know about Ghost problems. It appears I'm good at creating them. :P I've been online for over 20 years now, and I've been working as a developer for about 15 of those... Never had Session/Application problems before... Nor connection problems, but somehow, somewhere... This ghost has appeared... And no worries, I'm always at peace. I love programming, computers and the internet, and I will continue loving it, even if I have to kick my computer out of the window and buy a new one. :D
some-of-the-coding.txt
In the coding of Page_Load(), if I comment out ALL except for the DoConnOpen(...) and the DoConnClose(...) it STILL goes into the Application_End.
I also checked out the web.configs of my Test and 'official' programming, but I don't see any difference there... Sigh... Not getting closer yet.
P.S. Patrikt (why the extra t)... I know about Ghost problems. It appears I'm good at creating them. :P I've been online for over 20 years now, and I've been working as a developer for about 15 of those... Never had Session/Application problems before... Nor connection problems, but somehow, somewhere... This ghost has appeared... And no worries, I'm always at peace. I love programming, computers and the internet, and I will continue loving it, even if I have to kick my computer out of the window and buy a new one. :D
some-of-the-coding.txt
ASKER
P.S. Don't mind the crap that has creeped in by now... Tried a lot before actually asking a question... :P
I have one theory but only you can test it. Lets say that it is something "outside" what is closing application and your connection is only blocking this process when it is open. I mean that application is waiting for cleanup and than it ends.
This could be some Recycle process or some other code.
I suggest to put good logging into Application_Exit (may be Break point and check stack trace) and than play with IIS application pool settings. Also compare IIS settings (mainly app pool) of your Test app with real one iof there is some difference.
Patrik
Ps.: The additional T is from my Surname Trestik.
This could be some Recycle process or some other code.
I suggest to put good logging into Application_Exit (may be Break point and check stack trace) and than play with IIS application pool settings. Also compare IIS settings (mainly app pool) of your Test app with real one iof there is some difference.
Patrik
Ps.: The additional T is from my Surname Trestik.
ASKER
I'll look into that... I'll get back to you on it.
But you have to admit, it's some strange problem. :)
Thanks so far...
But you have to admit, it's some strange problem. :)
Thanks so far...
Problem is surely very strange and I'm personally interested in source of this behavior.
Few day before I have been solving another problem caused by external close of web application so I want to know what is this.
Patrik
Few day before I have been solving another problem caused by external close of web application so I want to know what is this.
Patrik
ASKER
Oh, I forgot to mention... I work with a 80Gig portable harddisk which I can connect at home (being the same drive letter etc.) as well, everything is set up to work the same at home and at the office. And the problem occurs there too... Not ruling out any settings of the SQL servers and IIS settings, but making it less logical that I've set it up faultly twice...
Anyway, I'll keep you posted as soon as I find something ;)
Anyway, I'll keep you posted as soon as I find something ;)
Also check if there is some even in even log (Application or System).
This can be caused by some unhandled exception outside of scope of request (see http://support.microsoft.com/kb/911816), but this should raise when debugger is attached so you can test it.
This can be caused by some unhandled exception outside of scope of request (see http://support.microsoft.com/kb/911816), but this should raise when debugger is attached so you can test it.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
:) Typical. I nearly see myself on your place.
If it another prove of true for rule "Computer everytime does EXACTLY what programer wanted. Only progremmer couldn't express his meaning EXACTLY"
I have to put his on my list "not to do".
And I also heve to lookup information about that file watch function and how to configure it. It can be usefull to have power ower it.
Have a nice day.
Patrik
If it another prove of true for rule "Computer everytime does EXACTLY what programer wanted. Only progremmer couldn't express his meaning EXACTLY"
I have to put his on my list "not to do".
And I also heve to lookup information about that file watch function and how to configure it. It can be usefull to have power ower it.
Have a nice day.
Patrik
On the first I have to say that as far as I know MySQL client has no connection pooling implemented so it is why your problem will not raise.
On second I have to say that it is whole wierd. If you are able to extract coide for test application it will be good to test it in another environment. If you are able to send it I can test it for you if you can.
I have never seen this problem even thet I work with SQL connection pooling every day in many applications.
Is there any reason to use Odbc instead of native MS SQL client?
Patrik