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. easy ADO error when opening catalog 'reference not set'

easy ADO error when opening catalog 'reference not set'

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
2 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.
  • R Offline
    R Offline
    Reveille
    wrote on last edited by
    #1

    Dim DBPath As String Dim ADOXcat As New ADOX.Catalog Dim sCreateString As String DBPath = System.Windows.Forms.Application.StartupPath() sCreateString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;" 'for Access 2007 Try 'Create DB ADOXcat.Create(sCreateString) Catch ex As System.Runtime.InteropServices.COMException 'create DB failed MsgBox(ex.Message(), MsgBoxStyle.Critical, "Failed to create database") Finally ADOXcat = Nothing End Try Dim ADOXtable As New ADOX.Table(), _ ADOXindex As New ADOX.Index(), _ Con As New ADODB.Connection() Try 'connect and insert tables Con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;") 'for 2007 MsgBox(Con.Errors().Count.ToString()) 'Displays 0 Errors MsgBox(Con.State.ToString()) 'Displays 1 representing an open connection 'Open the Catalog ADOXcat.ActiveConnection = Con 'Object reference not set to an instance of an object. I know this error usally gets generated when using a null object but if I receive no errors from opening the connection then 'Con' shouldnt be null right? Any help on this is greatly appreshated.

    M 1 Reply Last reply
    0
    • R Reveille

      Dim DBPath As String Dim ADOXcat As New ADOX.Catalog Dim sCreateString As String DBPath = System.Windows.Forms.Application.StartupPath() sCreateString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;" 'for Access 2007 Try 'Create DB ADOXcat.Create(sCreateString) Catch ex As System.Runtime.InteropServices.COMException 'create DB failed MsgBox(ex.Message(), MsgBoxStyle.Critical, "Failed to create database") Finally ADOXcat = Nothing End Try Dim ADOXtable As New ADOX.Table(), _ ADOXindex As New ADOX.Index(), _ Con As New ADODB.Connection() Try 'connect and insert tables Con.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & "\New07ADB.accdb;Jet OLEDB:Database Password=admin;") 'for 2007 MsgBox(Con.Errors().Count.ToString()) 'Displays 0 Errors MsgBox(Con.State.ToString()) 'Displays 1 representing an open connection 'Open the Catalog ADOXcat.ActiveConnection = Con 'Object reference not set to an instance of an object. I know this error usally gets generated when using a null object but if I receive no errors from opening the connection then 'Con' shouldnt be null right? Any help on this is greatly appreshated.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Your con is fine, it is the ADOXCat that is not instantiated!

      Quote from Great Outdoors: its a confident traveller who farts in India

      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