Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Unspecified Error in OleDB.oleDbConnection

Unspecified Error in OleDB.oleDbConnection

Scheduled Pinned Locked Moved Visual Basic
helpquestiondatabase
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SekharOne
    wrote on last edited by
    #1

    I get the unspecified error while connecting to the database. The Code i wrote for a class is as follows : Imports System.Data.SqlClient Public Class Conn ---------------------------------------- Dim con1 As OleDb.OleDbConnection Dim com1 As OleDb.OleDbCommand Dim da As OleDb.OleDbDataAdapter Dim ds As New DataSet Dim str As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & My.Application.Info.DirectoryPath & "\" & "MyDatabase.mdb'" ---------------------------------------- Public Function ExecuteNonQuery(ByVal SqlQuery As String) As String con1 = New OleDb.OleDbConnection(str) com1 = New OleDb.OleDbCommand(SqlQuery, con1) con1.Open() Try Return com1.ExecuteNonQuery Catch End Try End Function ----------------------------------------- I get the error as 'Unspecified error' at the line con1.open() I could not fugure out what is the problem ? could anybody help me out. Thanks in advance.

    Sekhar :)

    K 1 Reply Last reply
    0
    • S SekharOne

      I get the unspecified error while connecting to the database. The Code i wrote for a class is as follows : Imports System.Data.SqlClient Public Class Conn ---------------------------------------- Dim con1 As OleDb.OleDbConnection Dim com1 As OleDb.OleDbCommand Dim da As OleDb.OleDbDataAdapter Dim ds As New DataSet Dim str As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & My.Application.Info.DirectoryPath & "\" & "MyDatabase.mdb'" ---------------------------------------- Public Function ExecuteNonQuery(ByVal SqlQuery As String) As String con1 = New OleDb.OleDbConnection(str) com1 = New OleDb.OleDbCommand(SqlQuery, con1) con1.Open() Try Return com1.ExecuteNonQuery Catch End Try End Function ----------------------------------------- I get the error as 'Unspecified error' at the line con1.open() I could not fugure out what is the problem ? could anybody help me out. Thanks in advance.

      Sekhar :)

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      If you put the con1.Open() statement in the try block, perhaps you can get a better error message. Otherwise it could be a number of things. Are you sure your database is in the correct location in your file system? Are you sure your SqlQuery is a good SQL statement? You may also want to put some breakpoints in the code and run in debug...make sure that the values being passed into the function are what you are expecting. Hope this helps.

      S 1 Reply Last reply
      0
      • K Kschuler

        If you put the con1.Open() statement in the try block, perhaps you can get a better error message. Otherwise it could be a number of things. Are you sure your database is in the correct location in your file system? Are you sure your SqlQuery is a good SQL statement? You may also want to put some breakpoints in the code and run in debug...make sure that the values being passed into the function are what you are expecting. Hope this helps.

        S Offline
        S Offline
        SekharOne
        wrote on last edited by
        #3

        Thanks Kschuler for your response. I have tried this function from one Form and it is working fine , but when I am calling this from another form then it is showing me the error. Can you tell what might be the problem ? I had also put the con1.open() statement inside a try catch block but that is also showing me the same error message. Please Help.

        Sekhar :)

        K 1 Reply Last reply
        0
        • S SekharOne

          Thanks Kschuler for your response. I have tried this function from one Form and it is working fine , but when I am calling this from another form then it is showing me the error. Can you tell what might be the problem ? I had also put the con1.open() statement inside a try catch block but that is also showing me the same error message. Please Help.

          Sekhar :)

          K Offline
          K Offline
          Kschuler
          wrote on last edited by
          #4

          Maybe your connection is already open. You should replace con1.Open()with this: If con1.State <> ConnectionState.Open Then con1.Open() End If Also, you should put a Finally block on your try catch, and close the connection after you run an ExecuteNonQuery or an ExecuteScalar. You can use something similar to how you open it, like this: If con1.State <> ConnectionState.Closed Then con1.Close() End If Some other things I noticed in your code...you're importing sqlclient, but you are not using it, so you probably don't need to import it (unless you are using it in code that you didn't post) Also, you declared a dataadapter object, but you are not using that either (again, unless you just didn't post it)...you also might want to look at disposing objects when you are done with them. For example, once you've used the command object at the end of you function, you could dispose it. Hope this helps.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups