Access Database crashing on load in Vista
-
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!
-
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!
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 --
-
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!
From what I know there are no 64 bit ODBC drivers for MS Access
-
From what I know there are no 64 bit ODBC drivers for MS Access
It the application is specifically targeted to x86, it should default to use the 32-bit driver.