Answered by:
OleDbException (0x80004005): Could not find file

Question
-
User-1376164067 posted
Hello Everyone,
I have some light experience with Visual Studio and C# and I am experiencing a problem with my Access Database Connection and the Web Application. When I start debugging my site I get this error OleDbException (0x80004005): Could not find file (the path to my database file).
Here is my class file code:
// This function gets information from the tblStaffpublic static dsStaffSearch GetStaff(string Database){// declaration of variable for the dataset, connection, and data adapterdsStaffSearch DS;OleDbConnection sqlConn;OleDbDataAdapter sqlDA;// Creates a new connectionsqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +"Data Source=" + Database);// Gathers information from the tblStaffsqlDA = new OleDbDataAdapter("select * from tblStaff where StaffExperienec = 3", sqlConn);// Creates a new datasetDS = new dsStaffSearch();// Fills the object with information from tblStaffsqlDA.Fill(DS.tblStaff);// Passes data throughreturn DS;}// This function gets information from the tblStaff
public static dsStaffSearch GetStaff(string Database)
{
// declaration of variable for the dataset, connection, and data adapter
dsStaffSearch DS;
OleDbConnection sqlConn;
OleDbDataAdapter sqlDA;
// Creates a new connection
sqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Database);
// Gathers information from the tblStaff
sqlDA = new OleDbDataAdapter("select * from tblStaff where StaffExperienec = 3", sqlConn);
// Creates a new dataset
DS = new dsStaffSearch();
// Fills the object with information from tblStaff
sqlDA.Fill(DS.tblStaff);
// Passes data through
return DS;
}
and the code behind file:
// Creates Staff Search dataset variable
dsStaffSearch dsSearch = new dsStaffSearch();
// Calls Get Staff function to dsSearch
dsSearch = clsDataLayer.GetStaff(Server.MapPath("StaffingSystem_DB.mdb"));
// Set the DataGrid to the DataSource based on the table
grdStaff.DataSource = dsSearch.Tables["tblStaff"];
// Bind the DataGrid
grdStaff.DataBind();
when the error occurs it points to this specific line: sqlDA.Fill(DS.tblStaff);
From what I have read people are saying I dont have permissions to the db but this is on my personal machine and I have verified that I have read/write permissions. If anyone could provide me some assistance it would be greatly appreciated! Also here is the full error that is displayed in my web browser.
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: Could not find file 'C:\Users\Roc\Documents\Visual Studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\StaffingSystem_DB.mdb'.
Source Error:
Line 32: Line 33: // Fills the object with information from tblStaff Line 34: sqlDA.Fill(DS.tblStaff); Line 35: Line 36: // Passes data through
Source File: C:\Users\Roc\Documents\Visual Studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\clsDataLayer.cs Line: 34
Stack Trace:
[OleDbException (0x80004005): Could not find file 'C:\Users\Roc\Documents\Visual Studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\StaffingSystem_DB.mdb'.] System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +337 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126 System.Data.OleDb.OleDbConnection.Open() +43 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123 System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +166 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +115 StaffingServiceWebSite.clsDataLayer.GetStaff(String Database) in C:\Users\Roc\Documents\Visual Studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\clsDataLayer.cs:34 StaffingServiceWebSite.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\Roc\Documents\Visual Studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\WebForm1.aspx.cs:22 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Tuesday, November 30, 2010 11:30 PM
Answers
-
User-1199946673 posted
I have confirmed that the database exists in the above directory and I have also checked to make sure I have full privileges on the app_data folder inside of my project folderBut the path doesn't point to a mdb in the App_Data folder!!!
If the database is inside the App_Data folder, simply use:
"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|StaffingSystem_DB.mdb"
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 1, 2010 3:12 AM
All replies
-
User-1129879462 posted
It seems, for GetStaff method you are simply passing the database name instead of its fully qualified name like: 'C:\Users\Roc\Documents\Visual Studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\StaffingSystem_DB.mdb'
Make sure the db exists in the above location and directory has sufficient read/write privileges to create ldb files on the fly
Raj
Wednesday, December 1, 2010 12:37 AM -
User-1376164067 posted
Hey Raj,
Thank you for responding. I have confirmed that the database exists in the above directory and I have also checked to make sure I have full privileges on the app_data folder inside of my project folder. The only thing that bothers me is that when I right click the folder it says read only. I uncheck it and it asks if I want to do so the remaining folders and I click yes. However, when I go back and check that setting it goes back to read only. When I go into security though, I have full privileges to read/write etc...
I have also tried to change from my database name to the full path but it doesnt take, the back slashes present errors.
Wednesday, December 1, 2010 12:48 AM -
User-1199946673 posted
I have confirmed that the database exists in the above directory and I have also checked to make sure I have full privileges on the app_data folder inside of my project folderBut the path doesn't point to a mdb in the App_Data folder!!!
If the database is inside the App_Data folder, simply use:
"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|StaffingSystem_DB.mdb"
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 1, 2010 3:12 AM -
User-1376164067 posted
I was under the impression that as long as the webconfig file pointed to that location I was alright.
<configuration><connectionStrings><add name="StaffingSystem_DBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\StaffingSystem_DB.mdb"providerName="System.Data.OleDb" /></connectionStrings><system.web><compilation debug="true" targetFramework="4.0" /></system.web></configuration><configuration>
<connectionStrings>
<add name="StaffingSystem_DBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\StaffingSystem_DB.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
I did use that same path in my class file but when I try to keep the database variable to pass that database when the function is called it returns an error.
// Creates a new connection
sqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "Data Source=|DataDirectory|StaffingSystem_DB.mdb" + Database);
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.NotSupportedException: The given path's format is not supported.
Source Error:
Line 22: Line 23: // Creates a new connection Line 24: sqlConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "Data Source=|DataDirectory|StaffingSystem_DB.mdb" + Database); Line 25: Line 26: // Gathers information from the tblStaff
Source File: C:\Users\Roc\documents\visual studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\clsDataLayer.cs Line: 24
Stack Trace:
[NotSupportedException: The given path's format is not supported.] System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) +9368736 System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) +254 System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +85 System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath) +43 System.IO.Path.GetFullPath(String path) +91 System.Data.Common.ADP.GetFullPath(String filename) +31 System.Data.Common.DbConnectionOptions.ExpandDataDirectory(String keyword, String value, String& datadir) +5055036 System.Data.Common.DbConnectionOptions.ExpandDataDirectories(String& filename, Int32& position) +509 System.Data.OleDb.OleDbConnectionString..ctor(String connectionString, Boolean validate) +279 System.Data.OleDb.OleDbConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +36 System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +150 System.Data.OleDb.OleDbConnection.ConnectionString_Set(String value) +59 System.Data.OleDb.OleDbConnection.set_ConnectionString(String value) +4 System.Data.OleDb.OleDbConnection..ctor(String connectionString) +26 StaffingServiceWebSite.clsDataLayer.GetStaff(String Database) in C:\Users\Roc\documents\visual studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\clsDataLayer.cs:24 StaffingServiceWebSite.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\Roc\documents\visual studio 2010\Projects\StaffingServiceWebSite\StaffingServiceWebSite\WebForm1.aspx.cs:22 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Am I looking at this wrong? The goal is to on button click to fill a grid view with the selected criteria. I appreciate your response as well.Wednesday, December 1, 2010 12:30 PM -
User-1376164067 posted
Changed it! Thank you very much!
Wednesday, December 1, 2010 10:05 PM