473,406 Members | 2,816 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,406 software developers and data experts.

Irritating problem c# Ado.net

153 100+
I am developing one web app in which i need to connect to 6 access databases one at a time.
The problem is that the code does not work well properly, sometimes it gets stuck over
Executereader() function and when i use the debugger to know the value of Connection , Command
it 's shown as
Error: can not obtain value.(there is one sign of refresh button)
The same sign is for all the members of the connection object and all the onjects invloved like command and reader !
The problem is that the code jams sometims in the 1st database sometimes in the second etc etc.

How to get around this problem ?

Please help it's very urgent !
Dec 10 '08 #1
13 1689
nukefusion
221 Expert 100+
First thing I would probably do is review the code to make absolutely sure that you're closing all connections when finished with them.
I've seen similar things happen myself when connections aren't closed properly, so I'd eliminate that first and take it from there.
Dec 10 '08 #2
akshaycjoshi
153 100+
Thanks bro.
Here is the code
Expand|Select|Wrap|Line Numbers
  1.         While (isfound = False)
  2.             Try
  3.                 con = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;Persist Security Info=False; data source=" & Server.MapPath("App_data/PAT_ATT" & dbiterator.ToString() & ".mdb"))
  4.                 con.Open()
  5.                 If mode = "appno" Then
  6.                     cmd = New OleDbCommand("Select * from temp where appno = '" & appnumber & "'", con)
  7.                 Else
  8.                     cmd = New OleDbCommand("Select * from temp where cnm = '" & appname & "'" & " and dob='" & appdob & "'", con)
  9.                 End If
  10.                 reader = cmd.ExecuteReader()
  11.                 If reader.HasRows Then
  12.                     isfound = True
  13.                     Session("patravi2008searchedappno") = reader("appno").ToString()
  14.                     Session("patravi2008founddatabase") = dbiterator
  15.                     LabelRoll.Text = reader("rol").ToString
  16.                     LabelName.Text = reader("cnm").ToString
  17.                     LabelFName.Text = reader("fnm").ToString
  18.                     LabelappNo.Text = reader("AppNo").ToString
  19.                     LabelCat.Text = reader("cat").ToString
  20.                     LabelDOB.Text = reader("dob").ToString
  21.                     Labelsex.Text = reader("sex").ToString
  22.                     LabelClass.Text = reader("class").ToString
  23.                     Labelcentre.Text = reader("cnt_cd").ToString & " --" & reader("cnt_nm").ToString
  24.                     LabelCN.Text = reader("vypno").ToString
  25.                     studentimage.ImageUrl = "patravi2008showpic.aspx?"
  26.                     sign.ImageUrl = "patravi2008showsign.aspx?"
  27.                 End If
  28.  
  29.             Catch ex As Exception
  30.  
  31.             Finally
  32.                 If con.State = ConnectionState.Open Then
  33.                     con.Close()
  34.                     con = Nothing
  35.                 End If
  36.  
  37.                 If reader.IsClosed = False Then
  38.                     reader.Close()
  39.                 End If
  40.                 dbiterator = dbiterator + 1
  41.             End Try
  42.  
I dont think there is some problem in the code.
One imp thing is that i can see some thread.ThreadabortException in mscorlib.dll in the output window.
Is there any relation with that ?

PS:It's very urgent.
Dec 11 '08 #3
akshaycjoshi
153 100+
I can also see some "code has exited with code 0" three times in the output window.
Dec 11 '08 #4
Ramk
61
Try changing the order of releasing in the finally block as shown below, also, include the null check before you access the object...
Expand|Select|Wrap|Line Numbers
  1. Finally
  2. If reader <> Nothing and reader.IsClosed = False Then
  3. reader.Close()
  4. End If
  5.  
  6. If con <> Nothing con.State = ConnectionState.Open Then
  7. con.Close()
  8. con = Nothing
  9. End If
  10.  
  11. dbiterator = dbiterator + 1
  12. End Try
  13.  
Dec 11 '08 #5
Ramk
61
@Ramk
hi akshay,
did your problem is solved?
Dec 12 '08 #6
akshaycjoshi
153 100+
I came to know that that it was happening coz of the slow OleDbConnection and OleDbCommand.
As far as "Value not shown" error, it was coz of the fact that the fuction was getting executed somewhere else (System.Data.dll) so the debugger is unable to obtain the data for al the objects involved (Connection,Comand and reader)
Dec 12 '08 #7
Frinavale
9,735 Expert Mod 8TB
After reviewing the code you've posted I don't see where you are connecting to 6 Access databases at the same time.

You will see a thread.ThreadabortException when you redirect to a new page...this aborts the current thread before it's finished executing. If you specify the URL and a Boolean as parameters for the Redirect() method you can avoid these errors.


Are you seeing the ADO errors in your Catch block?

-Frinny
Dec 15 '08 #8
Plater
7,872 Expert 4TB
Well I see that you are only trying to close the connection if the state is "open"
What if it is in one of the other states? Then it gets left open, and the jet DB driver will be angry
Dec 15 '08 #9
akshaycjoshi
153 100+
@Frinavale

See the while loop.
Also i am not connecting to 6 access databases at the same time, it's one by one i am iterating over them.
Dec 16 '08 #10
akshaycjoshi
153 100+
@Plater
yes a good point.Now i guess the code should be
if(con.State <> ConnectionState.Close)
Con.Close()

?
Dec 16 '08 #11
Plater
7,872 Expert 4TB
@akshaycjoshi
It probably wouldn't hurt. Can't be sure if it will solve problem or not
Dec 16 '08 #12
akshaycjoshi
153 100+
@Plater
Can a broken connection be closed ?
I have hunch.
Dec 17 '08 #13
Plater
7,872 Expert 4TB
I guess if you really wanted to, you could switch on the connectionstate and look to see if it ever comes back in an odd state.
I have not run into a problem closing a broken connection before, that I am aware of.
Dec 17 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Levent | last post by:
Folks, I am getting following message from pear. I am running RedHat 8.0, PostgreSQL is 7.3.2 PHP Version 4.2.2 and pear:db 1.6.5. Warning: pg_errormessage(): supplied argument is not a valid...
6
by: Park997 | last post by:
Hi, I have a script that runs correctly in IDLE, runs correctly when invoked in the Command Prompt (Win XP), runs correctly from Komodo, but flashes a black box too fast to see when the icon is...
0
by: sachin bond | last post by:
The following code(in c++) is supposed to divide a file into 'n' different files. suppose i'm having a file called "input.zip". The execution of the following code should divide "input.zip"...
3
by: Deano | last post by:
My form is set up so that if I add a record to my main form, a related record is created in the subform. This occurs in the afterupdate event of my main control. I have made a few changes here,...
0
by: Gorgen | last post by:
I have a namespace LogRead with one class in it: LogReadWindow I want to program doing a protoype so I write LogRead.ReadLog() on an apropiate place. But it is always changed to...
3
by: Bruno van Dooren | last post by:
Hi all, i am working a some C++ software that will run both on windows and linux. development is done on windows with VS .NET 2003. when i view and edit source files on linux (using Vim), all...
2
by: PJ6 | last post by:
I have no idea why, but when I place breakpoints when running one of my applications in debug mode, they never appear where I want them to, sometimes they even pop up in a different method than the...
0
by: Axel Dahmen | last post by:
Hi, when I'm opening the ASP.NET 2.0 Website Configuration Manager in IIS I get quite confused about the values it displays at the Application tab. For example, it states I'd be using af-ZA as...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
4
Ali Rizwan
by: Ali Rizwan | last post by:
Hi I have problem from a couple of years it is the runouce problem how can i solve it it cannot be deleted from taskmanager and not from regestiry can some body help me? Thanx
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
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...

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.