简体   繁体   English

Windows窗体程序找不到mdb文件(C:\ windows \ system32 \ qbcdb.mdb)

[英]Windows Form program can not find mdb file (C:\windows\system32\qbcdb.mdb)

Recently I have run into the issue of the C# program I am creating throwing an exception Could not find file C:\\windows\\system32\\qbcdb.mdb . 最近我遇到了C#程序的问题我正在创建抛出异常Could not find file C:\\windows\\system32\\qbcdb.mdb It's odd because I have never ran into this issue before when deploying my program via Advanced Installer. 这很奇怪,因为在通过Advanced Installer部署我的程序之前,我从未遇到过这个问题。 I didn't change anything but for some reason this error keeps happening (screenshot of the exception box - http://imgur.com/1GLhwmg ). 我没有改变任何东西,但由于某种原因,这个错误不断发生(例外框的屏幕截图 - http://imgur.com/1GLhwmg )。

I've no idea on what to include in this question to help explain my problem more, so here is my App.config file (read on a site it may be tied to that, but again, I've never had any issues so far): 我不知道在这个问题中包含哪些内容可以帮助更多地解释我的问题,所以这是我的App.config文件(在网站上阅读它可能与之相关,但同样,我从来没有遇到任何问题所以远):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="QBC.Properties.Settings.qbcdbConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\qbcdb.mdb"
            providerName="System.Data.OleDb" />
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

Insert into db method: 插入db方法:

#region inserts the data into the database
private void InsertData()
{
   using (dbConn)
   {
      dbConn.Open();

            using (dbCmd = new OleDbCommand("INSERT INTO members (household_head, birthday, phone, email, address, status, spouse, spouse_birthday, spouse_phone, spouse_email, " +
              "anniversary, spouse_status, child1, child1_birthday, child1_email, " +
         "child2, child2_birthday, child2_email, child3, child3_birthday, child3_email, child4, child4_birthday, child4_email, child5, child5_birthday, child5_email," +
         "child6, child6_birthday, child6_email, child7, child7_birthday, child7_email) " +
         "VALUES (@txtBox_householdHead, @txtBox_householdHeadBirthday, @txtBox_householdHeadPhone, @txtBox_householdHeadEmail, @txtBox_householdHeadAddress, @txtBox_householdHeadStatus, " +
         "@txtBox_spouse, @txtBox_spouseBirthday, @txtBox_spousePhone, @txtBox_spouseEmail, @txtBox_Anniversary, @txtBox_spouseStatus, " +
         "@txtBox_child1, @txtBox_child1Birthday, @txtBox_child1Email, " +
         "@txtBox_child2, @txtBox_child2Birthday, @txtBox_child2Email, @txtBox_child3, @txtBox_child3Birthday, @txtBox_child3Email, @txtBox_child4, @txtBox_child4Birthday, @txtBox_child4Email, " +
         "@txtBox_child5, @txtBox_child5Birthday, @txtBox_child5Email, @txtBox_child6, @txtBox_child6Birthday, @txtBox_child6Email, @txtBox_child7, @txtBox_child7Birthday, @txtBox_child7Email)", dbConn))
            {
                try
                {
                    InsertDBParameters(ref dbCmd);

                    dbCmd.ExecuteNonQuery();
                }
                catch (OleDbException ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
                finally
                {
                    dbConn.Close();
                }
            }


            MessageBox.Show("Record inserted.");

            ClearAll(this);
        }


}
#endregion


#region creates the db parameters
private void InsertDBParameters(ref OleDbCommand cmd)
{

    foreach (Control c in Controls)
    {
        if (c is TextBox)
        {
            listOfTextboxes.Add(new KeyValuePair<string, string>(((TextBox)c).Name, ((TextBox)c).Text));
            }
        }

        for (int i = 0; i < listOfTextboxes.Count; i++)
        {
            cmd.Parameters.AddWithValue(String.Format("@{0}", listOfTextboxes[i].Key.ToString()), listOfTextboxes[i].Value);
        }



 }
 #endregion

Select from db method - 从db方法中选择 -

#region displays all members in the database
private void MenuViewMembers_Click(object sender, EventArgs e)
{
        // hide any controls left that may be left over from another option
        HideAllControls(this);



        qbcDataGridView.Font = new Font(qbcDataGridView.Font.FontFamily, 10);

        qbcDataGridView.Location = new Point(30, 100);

        qbcDataGridView.Size = new Size(1500, 500);


        dbConn.Open();

        DataTable dt = new DataTable();


        DbAdapter = new OleDbDataAdapter("select ID, household_head AS head, birthday, phone, email, address, status, spouse, spouse_birthday AS sbirthday, spouse_email AS semail, anniversary," +
            " spouse_status AS sstatus," +
            "child1, child1_birthday AS birthday1, child1_email AS email1, child2, child2_birthday AS birthday2, child3, child3_birthday AS birthday3, child3_email AS email3, " +
            "child4, child4_birthday AS birthday4, child4_email AS email4, child5, child5_birthday AS birthday5, child5_email AS email5," +
            "child6, child6_birthday AS birthday6, child6_email AS email6, child7, child7_birthday AS birthday7, child7_email AS email7 from members", dbConn);
        DbAdapter.Fill(dt);

        for (int i = dt.Columns.Count - 1; i >= 0; i--)
        {
            if (dt.AsEnumerable().All(row => row[i].ToString() == ""))
            {
                dt.Columns.RemoveAt(i);
            }
        }

        qbcDataGridView.DataSource = dt;


        qbcDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

        qbcDataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

        qbcDataGridView.DefaultCellStyle.WrapMode = DataGridViewTriState.True;


        dbConn.Close();

        Controls.Add(qbcDataGridView);
}
#endregion

Inside visual studio, it runs fine, but when I build a msi for it with advanced installer, I receive that error message when I try to insert/select from the database. 在visual studio中,它运行正常,但是当我使用高级安装程序为它构建msi时,当我尝试从数据库插入/选择时,我收到该错误消息。

I'm sorry if this is not enough information, I don't know what really to provide to help explain my situation. 如果这些信息不够,我很抱歉,我不知道提供什么来帮助解释我的情况。

Thanks! 谢谢!

First of all, C:\\windows\\system32\\ is not the right place to store your runtime data. 首先,C:\\ windows \\ system32 \\ 不是存储运行时数据的正确位置。 This approach was not valid since Windows 95 went out of Fashion and even there it only worked because FAT had no way to prevent this. 这种方法无效,因为Windows 95已经过时尚,甚至只有它才有效,因为FAT无法阻止这种情况。 In particular that folder is protected both via rights and processes like Virtualsiation . 特别是该文件夹通过权限和进程(如Virtualsiation )受到保护。 And this will propably only get worse in the future. 而这将在未来变得更糟。 So best to not even start with it. 所以最好不要从它开始。

The "proper" place to store this kind of data is in one of the Special Folders . 存储此类数据的“正确”位置在其中一个特殊文件夹中 Either the User Specific one or a Windows Wide one. 用户特定的一个或Windows宽的一个。 ApplicationData and CommonApplicationData should be the best place for this. ApplicationData和CommonApplicationData应该是最好的选择。

Note that the cross user places will get you into issues if more then one user runs the programm (runas, switch user) and handles are not quickly released. 请注意,如果多个用户运行该程序(runas,切换用户)并且不会快速释放句柄,则跨用户位置将使您遇到问题。 Generally the target should be asumed to not be writeable/only writeable in short bursts if it is a cross user folder. 通常,如果目标是跨用户文件夹,则应该将目标设置为不可写/仅可在短突发中写入。

When I build a msi for it with advanced installer, I receive that error message when I try to insert/select from the database. 当我使用高级安装程序为它构建一个msi时,当我尝试从数据库插入/选择时,我收到该错误消息。

To troubleshoot this you will need a tool called Process Monitor . 要解决此问题,您需要一个名为Process Monitor的工具。 Proces sMonitor traces HDD, Registry, Events & Processes in real-time. Proces sMonitor实时跟踪HDD,注册表,事件和进程。

Quickly Start the trace, reproduce the error and quickly Stop the trace when it fails. 快速启动跟踪,重现错误并在失败时快速停止跟踪。 Then investigate ProcMon's (Filemon) log to see where the application is looking for the AccessDB it cant find. 然后调查ProcMon的(Filemon)日志,看看应用程序在哪里寻找它找不到的AccessDB。 It will be a ACCESS DENIED or a Path Not Found . 这将是一个ACCESS DENIED或未Path Not Found

From here you can determine where the file should be located. 从这里,您可以确定文件的位置。 I suspect it will be something like a users permissions to the C:\\Windows\\system32 is denied.Or the user has a D:\\ drive Operating System instead of C:\\ or something like that which you can fix probably by specifying the data directory properly. 我怀疑它会像用户对C:\\ Windows \\ system32的权限被拒绝。或者用户有一个D:\\驱动操作系统而不是C:\\或类似的东西你可以通过指定数据来修复目录正确。

As a rule of thumb don't use System32 as a dumping ground for your files. 根据经验,不要将System32用作文件的转储地。 The Access Database should be in Program Files, or the users Data directory, or on a FileShare (if used by > 1 person). Access数据库应位于Program Files,用户Data目录或FileShare上(如果由> 1人使用)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到文件 &#39;c:\\windows\\system32\\inetsrv\\xxx.xlsx&#39; - Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx' ASP零:System.IO.FileNotFoundException:找不到文件&#39;c:\\ windows \\ system32 \\ inetsrv \\ log4net.config&#39; - ASP Zero :System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\log4net.config' File.Move错误-System.IO.FileNotFoundException:找不到文件&#39;c:\\ windows \\ system32 \\ inetsrv - File.Move Error - System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv 在c#Windows桌面应用程序中动态附加mdb数据库文件 - dynamically attach mdb database file in c# windows desktop application 拒绝访问路径“ C:\\ Windows \\ System32 \\” - Access to the path 'C:\Windows\System32\ is denied 访问路径 &#39;c:\windows\system32\inetsrv\config\&#39; 被拒绝 - Access to the path 'c:\windows\system32\inetsrv\config\' is denied 为什么我收到这个错误: System.UnauthorizedAccessException: &#39;C:\\Windows\\system32\\CSV_file&#39; - why to I get this error: System.UnauthorizedAccessException: 'C:\Windows\system32\CSV_file' 如何通过C#语言删除Windows 7 dll文件(在System32文件夹中) - How Delete A Windows 7 dll File (In System32 Folder) By C# Language 当程序集位于“C:\Windows\System32”内时,我得到“无法找到运行此应用程序的运行时版本” - When assembly is inside 'C:\Windows\System32' i get 'Unable to find a version of the runtime to run this application' 找不到路径的一部分 'C:\\Windows\\System32\\oobe\\info\\Backgrounds - Could not find a part of the path 'C:\\Windows\\System32\\oobe\\info\\Backgrounds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM