Solved

Occasional OleDbException: Unspecified Error

Posted on 2006-07-20
5
1,957 Views
Last Modified: 2009-11-16
I'm working on an asp.net 2.0 website that connects to a microsoft access database using an OleDb connection.  Most of the time the site works perfectly fine, but every once in a while I get the following error when the site tries to open the connection object...

System.Data.OleDb.OleDbException: Unspecified error

Here's the stack trace...

[OleDbException (0x80004005): Unspecified error]
   System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1054929
   System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.OleDb.OleDbConnection.Open() +37
   common.GetUserID(String strLogin) in C:\Inetpub\wwwroot\CapCal\App_Code\common.vb:130
   CapCal.offers_view.LoadOffers() in C:\Inetpub\wwwroot\capcal\offers\view.aspx.vb:116
   CapCal.offers_view.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\capcal\offers\view.aspx.vb:14
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

And here's my code...

   Public Function GetUserID(ByVal strLogin As String) As Integer
        Dim objConn As New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Forums").ToString)
        Dim cmdGet As New OleDbCommand("", objConn)
        Dim objReader As OleDbDataReader
        Dim strQuery As String

        If strLogin <> "Not Logged In" Then
            objConn.Open()
            strQuery = "SELECT UserID FROM Users WHERE Login = '" & strLogin & "';"
            cmdGet.CommandText = strQuery
            cmdGet.CommandType = CommandType.Text

            objReader = cmdGet.ExecuteReader

            If objReader.Read Then
                Return objReader("UserID")
            Else : Return -1
            End If

            objReader.Close()
            objConn.Close()

            cmdGet.Dispose()
            objConn.Dispose()

            objReader = Nothing
            cmdGet = Nothing
            objConn = Nothing
        End If

    End Function

It fails on the objConn.Open().  And, once the error is thrown, every page that accesses the database will throw the same error no matter what.  The only thing that I can do to get rid of it is to restart IIS, rebuild the website, or let the server sit for 5 to 10 minutes without any traffic.

I've already scoured the site and made sure that every single connection is closed as soon as I'm done using it.  As you can see above, I've become very strict about closing and disposing of everything.

Most of the time the error is completely random, but I can recreate it consistantly by going to one of the pages, and then just hitting reload.

Any ideas?
0
Comment
Question by:TheKyle
5 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 345 total points
ID: 17162990
Try this different approach, using ExecuteScalar instead of the OleDataReader:

  Public Function GetUserID(ByVal strLogin As String) As Integer

    Using objConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("Forums").ToString)

      Using cmdGet As New OleDbCommand(String.Format("SELECT UserID FROM Users WHERE Login = '{0}' ", strLogin), objConn)

        If strLogin <> "Not Logged In" Then

          Try
            objConn.Open()
            Dim userID As Integer = cmdGet.ExecuteScalar()
          Catch ex As Exception
             System.Diagnostic.Debug.WriteLine(ex.ToString())
          End Try

          Return userID

        End If

      End Using
    End Using

    Return ""

  End Function

NOTE:  The Using blocks will automatically call the Close/Dispose method at the end, so you don't need to add it.

Bob
0
 
LVL 6

Author Comment

by:TheKyle
ID: 17386714
TheLearnedOne -
So TheLearnedOne is recommending that I accept the answer given by TheLearnedOne?  Hmmmm...  That sounds a little shady to me....  heheh :)
 
Sorry I havn't had a chance to get back to this.  I've been extremely busy on other projects, so I completely forgot.  I actually saw your answer a while back, but never found time to try it out before completely forgetting about it. :(  I'm sorry.

I don't think that the solution above will completely solve my problem, though.  I also saw the same error show up on another function that returned more than just a single scalar value.  That's what was so weird about the error.  It only showed up once in a while, and sometimes it showed up in different places.

The other thing is that it showed up on the connection.open call, so I don't think that the data reader vs. execute scalar change would help either.

Unfortunately, I still don't have time to try it out since I have a huge deadline more than "4 days" from now, and since the error is so hard to consistantly replicate.  So, I guess unless someone comes up with another solution in the next 4 days the points will be going to you.

I do really appreciate your help, btw.  I really don't mean to bash on your answer.  At this point I appreciate all the help I can get.

Thanks!
0
 

Expert Comment

by:w247be
ID: 25834197
I have the same problem, only 2 of 50 websites who are using the same code get an error since last week, ... website worked more then 1 year perfect before ...

Unspecified error
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.Data.OleDb.OleDbException: Unspecified error

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[OleDbException (0x80004005): Unspecified error]
   System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1152785
   System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.OleDb.OleDbConnection.Open() +37
   Admin.GetContent(String culture, String id) +238
   rates.Page_Load(Object sender, EventArgs e) +269
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

 

=================

 Function GetContent(ByVal culture As String, ByVal id As String) As OleDbDataReader
        Dim Conn As OleDbConnection
        Dim mDR As OleDbDataReader
        Dim objCommand As New OleDbCommand
        Dim strConn As String = ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString


        Dim mystring As String = "SELECT Content.Text, Content.Content1, Content.Content2, Content.Content3, Content.Content4, Content.Content5, Content.ContentID, Content.Description, Content.Keywords, Content.Color, Cultures.Culture, Pages.PageID " & _
        "FROM Templates INNER JOIN (Cultures INNER JOIN (Pages INNER JOIN Content ON Pages.PageID = Content.PageID) ON Cultures.CultureID = Content.CultureID) ON Templates.TemplateID = Content.TemplateID " & _
        "WHERE (((Cultures.Culture)=@culture) AND ((Pages.PageID)=@id));"


        Conn = New OleDbConnection(strConn)
        Dim Cmd As New OleDbCommand(mystring, Conn)

        Dim parameterStatus As OleDbParameter = New OleDbParameter("@culture", OleDbType.VarChar)
        parameterStatus.Value = culture
        Cmd.Parameters.Add(parameterStatus)

        Dim parameterid As OleDbParameter = New OleDbParameter("@id", OleDbType.VarChar)
        parameterid.Value = id
        Cmd.Parameters.Add(parameterid)

        Conn.Open()
        mDR = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
        Return mDR

        mDR.Close()
        Conn.Close()
        Conn = Nothing

    End Function
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now