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. C#
  4. Access Database crashing on load in Vista

Access Database crashing on load in Vista

Scheduled Pinned Locked Moved C#
databasetestingdebuggingbeta-testinghelp
4 Posts 3 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.
  • H Offline
    H Offline
    Hitchic05
    wrote on last edited by
    #1

    I've got a program I've written that uses an Access Database for a backend. I've been using it on XP for awhile now with no issues. However recently I've got a new user who has Vista 64 bit. My application crashes before it even finishes loading. Using some debug code in a custom compile I did for him I've narrowed it down to the following section of code:

    string sAppPath = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).Replace("file:\\", "");
    public System.Data.OleDb.OleDbConnection DBConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + (sAppPath + "\\Database.mdb"));

    sSQLStatement = ("SELECT Filename FROM Scriptures");
    System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sSQLStatement, DBConnection);

    try
    {
    if (DBConnection.State.ToString() == "Closed") DBConnection.Open();

    // Create the datareader object to connect to table
    System.Data.OleDb.OleDbDataReader DataReader = SQLCommand.ExecuteReader();
    
    // Did we get anything?
    while (DataReader.Read())
    {
        // Do some manipulation
    }
    
    // Close the reader 
    DataReader.Close();
    
    // Close the connection. Its important.
    DBConnection.Close();
    

    }

    The program crashes on this line:

    if (DBConnection.State.ToString() == "Closed") DBConnection.Open();

    I'm at a loss as to why this would work on XP but not Vista. I don't have a Vista machine readily available for testing at this time. Any help would be greatly appreciated. Thanks!

    D R 2 Replies Last reply
    0
    • H Hitchic05

      I've got a program I've written that uses an Access Database for a backend. I've been using it on XP for awhile now with no issues. However recently I've got a new user who has Vista 64 bit. My application crashes before it even finishes loading. Using some debug code in a custom compile I did for him I've narrowed it down to the following section of code:

      string sAppPath = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).Replace("file:\\", "");
      public System.Data.OleDb.OleDbConnection DBConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + (sAppPath + "\\Database.mdb"));

      sSQLStatement = ("SELECT Filename FROM Scriptures");
      System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sSQLStatement, DBConnection);

      try
      {
      if (DBConnection.State.ToString() == "Closed") DBConnection.Open();

      // Create the datareader object to connect to table
      System.Data.OleDb.OleDbDataReader DataReader = SQLCommand.ExecuteReader();
      
      // Did we get anything?
      while (DataReader.Read())
      {
          // Do some manipulation
      }
      
      // Close the reader 
      DataReader.Close();
      
      // Close the connection. Its important.
      DBConnection.Close();
      

      }

      The program crashes on this line:

      if (DBConnection.State.ToString() == "Closed") DBConnection.Open();

      I'm at a loss as to why this would work on XP but not Vista. I don't have a Vista machine readily available for testing at this time. Any help would be greatly appreciated. Thanks!

      D Offline
      D Offline
      Douglas Troy
      wrote on last edited by
      #2

      First off, you really need to get yourself a good C# book and do some reading, because you have some serious fundamental flaws in your code. The Database connection State is an Enumerated type (see example usage[^]), you need not cast it to a String and then compare, you should be comparing the Enumerated types. Additionally, you should really make use of Using[^] statements in your code, it will make for cleaner code, and will ensure the objects are probably closed and disposed. I see one potential problem, in that you're creating an instance of a SQLCommand using a connection object that might be null; and to top it off, you're doing that outside the scope of your Try/Catch block. See this line: System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sSQLStatement, DBConnection); If you're not sure if the connection has been created and opened, then you should do that first. Once you have a valid connection, THEN create your SQL Command and hook that up to the connection and execute your query (see Example[^] on MSDN) But seriously, go read about Enumerated types and Using statements, and hopefully this will help you over come your problem.


      Last modified: 13mins after originally posted --

      1 Reply Last reply
      0
      • H Hitchic05

        I've got a program I've written that uses an Access Database for a backend. I've been using it on XP for awhile now with no issues. However recently I've got a new user who has Vista 64 bit. My application crashes before it even finishes loading. Using some debug code in a custom compile I did for him I've narrowed it down to the following section of code:

        string sAppPath = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).Replace("file:\\", "");
        public System.Data.OleDb.OleDbConnection DBConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + (sAppPath + "\\Database.mdb"));

        sSQLStatement = ("SELECT Filename FROM Scriptures");
        System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sSQLStatement, DBConnection);

        try
        {
        if (DBConnection.State.ToString() == "Closed") DBConnection.Open();

        // Create the datareader object to connect to table
        System.Data.OleDb.OleDbDataReader DataReader = SQLCommand.ExecuteReader();
        
        // Did we get anything?
        while (DataReader.Read())
        {
            // Do some manipulation
        }
        
        // Close the reader 
        DataReader.Close();
        
        // Close the connection. Its important.
        DBConnection.Close();
        

        }

        The program crashes on this line:

        if (DBConnection.State.ToString() == "Closed") DBConnection.Open();

        I'm at a loss as to why this would work on XP but not Vista. I don't have a Vista machine readily available for testing at this time. Any help would be greatly appreciated. Thanks!

        R Offline
        R Offline
        Razvan Dimescu
        wrote on last edited by
        #3

        From what I know there are no 64 bit ODBC drivers for MS Access

        D 1 Reply Last reply
        0
        • R Razvan Dimescu

          From what I know there are no 64 bit ODBC drivers for MS Access

          D Offline
          D Offline
          Douglas Troy
          wrote on last edited by
          #4

          It the application is specifically targeted to x86, it should default to use the 32-bit driver.

          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