Answered by:
System.Data.OleDb.OleDbException: Unspecified error

Question
-
User692778923 posted
I have built a web site for checking the students homeworks. Site is generally working fine. But sometimes it gives the error
System.Data.OleDb.OleDbException: Unspecified error .
When I uploaded my aspx pages which are used to enter or show the marks . Then site starts working well again.
I tried using closing all the connections to the database as soon as possible.
Some datagrids are using sqldatasource to connect to the database and i also make sqldatasource.dispose as soon as possible.
i also added <identity impersonate="false" userName="" password="" /> to the web config file
The strange thing is that when this error occurs. I just can remove it by opening the web config file and then saving it again.
I know i am not for now giving anycodes .But i don't know which to mention here would be helpful
Hope someone can response
Thx
Friday, April 11, 2014 7:18 PM
Answers
-
User281315223 posted
This could be related to how you are actually opening your database and related database connections.
I always recommend using a using statement when handling things like this as it will ensure that all of your connections are properly opened, closed and disposed of after use as seen below :
using(var oleDbConnection = new OleDbConnection("Your Connection String")) { // Open your Connection oleDbConnection.Open(); // Build your query var sql = "INSERT INTO YourTable VALUES(@Student,@Grade)"; // Build a command to execute your query var oleDbCommand = new OleDbCommand(sql,oleDbConnection); // Add any parameters oleDbCommand.Parameters.AddWithValue("@Student", StudentTextBox.Text); oleDbCommand.Parameters.AddWithValue("@Grade", StudentGradeTextBox.Text); // Execute your query oleDbCommand.ExecuteNonQuery(); }
If there is any additional code that you are using or that you could provide, it might be extremely helpful.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, April 12, 2014 12:03 AM
All replies
-
User281315223 posted
This could be related to how you are actually opening your database and related database connections.
I always recommend using a using statement when handling things like this as it will ensure that all of your connections are properly opened, closed and disposed of after use as seen below :
using(var oleDbConnection = new OleDbConnection("Your Connection String")) { // Open your Connection oleDbConnection.Open(); // Build your query var sql = "INSERT INTO YourTable VALUES(@Student,@Grade)"; // Build a command to execute your query var oleDbCommand = new OleDbCommand(sql,oleDbConnection); // Add any parameters oleDbCommand.Parameters.AddWithValue("@Student", StudentTextBox.Text); oleDbCommand.Parameters.AddWithValue("@Grade", StudentGradeTextBox.Text); // Execute your query oleDbCommand.ExecuteNonQuery(); }
If there is any additional code that you are using or that you could provide, it might be extremely helpful.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, April 12, 2014 12:03 AM -
User692778923 posted
Thank you for your reply. As u said i tried to check all my connections opened and closed after use. I think it is better not to give my code here because
i write the code not very reader friendly, i wanted to complete all thing at one page, so i didn't use a menu and session variable
i used 4 panels in a single aspx page and put 4 buttons at the top and made the panels visible and invisible according to the buttons used as menu button at top.
Some panels are including datagrids and sqldatasource objects. I know this is not a good way to move on but i did it this way.
Now i tried as i said closing all connections and dispose them etc...
I will now wait and inspect the site behaviour. If it doesnt't go well , then i am thinking of using session thing and putting a java menu at top and using single aspx pages
instead of one large with panels in it.
Thx again for your reply
Saturday, April 12, 2014 7:00 PM -
User-1199946673 posted
I think it is better not to give my codeWe think it's better that you do!!!! How can we know if your code isn't the problem, if you don't show it to us?
because i write the code not very reader friendly
An you don't want us to comment on that and make your code more reader friendly?
Now i tried as i said closing all connections and dispose them etc...So please show us?
I will now wait and inspect the site behaviour. If it doesnt't go well , then i am thinking of using session thing and putting a java menu at top and using single aspx pages
instead of one large with panels in it.
I think what you're looking for is a Masterpage
Sunday, April 13, 2014 4:49 AM