Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 外部组件引发异常_C#_Wpf_Ms Access_Caliburn.micro - Fatal编程技术网

C# 外部组件引发异常

C# 外部组件引发异常,c#,wpf,ms-access,caliburn.micro,C#,Wpf,Ms Access,Caliburn.micro,我有个问题。我有Access数据库和WPF应用程序。应用程序是32位构建的,Access数据库是32位的。当连接到数据库时,应用程序每隔一段时间就会显示一个错误。。外部组件抛出异常。eavn如果我发现了这个错误,或者再次尝试连接到数据库,它将无法工作。我必须重新启动应用程序,然后它再次工作,直到它在下一个大约15个数据库连接事务中抛出并再次出错。如果你知道我的意思 如何重新启动该错误,以便再次连接到数据库或eavn以防止引发错误 请帮帮我。 我不知道提供什么样的代码才是相关的 t

我有个问题。我有Access数据库和WPF应用程序。应用程序是32位构建的,Access数据库是32位的。当连接到数据库时,应用程序每隔一段时间就会显示一个错误。。外部组件抛出异常。eavn如果我发现了这个错误,或者再次尝试连接到数据库,它将无法工作。我必须重新启动应用程序,然后它再次工作,直到它在下一个大约15个数据库连接事务中抛出并再次出错。如果你知道我的意思

如何重新启动该错误,以便再次连接到数据库或eavn以防止引发错误

请帮帮我。 我不知道提供什么样的代码才是相关的

        try
        {
            List<IDModel> output = new List<IDModel>();
            using (OleDbConnection connection = new OleDbConnection(Conn))
            {
                await connection.OpenAsync();
                using (OleDbCommand Command = new OleDbCommand("SELECT * FROM DATA WHERE [STATUS] = @status;", connection))
                {

                    Command.Parameters.AddWithValue("@status", _status);

                    var reader = await Command.ExecuteReaderAsync();

                    while (reader.Read())
                    {

                        output.Add(InsertID
                                            ((int)reader["ID"], (string)reader["STANDARD"], (string)reader["NAZIV"], (string)reader["POSLOVNA ENOTA"],
                                            (string)reader["IZVOR NESKLADNOSTI"], (string)reader["ODDELEK"], (string)reader["OPIS"],

                                            (string)reader["SLIKA 1"].ToString(),
                                            (string)reader["SLIKA 2"].ToString(), (string)reader["SLIKA 3"].ToString(), (string)reader["SLIKA 4"].ToString(),
                                            (string)reader["SLIKA 5"].ToString(), (string)reader["EXCEL 1"].ToString(), (string)reader["PDF 1"].ToString(),

                                            (string)reader["SLIKA 6"].ToString(), (string)reader["EXCEL 2"].ToString(), (string)reader["PDF 2"].ToString(),
                                            (string)reader["KOREKCIJA"].ToString(),

                                            (string)reader["SLIKA 7"].ToString(), (string)reader["EXCEL 3"].ToString(), (string)reader["PDF 3"].ToString(),
                                            (string)reader["KOREKTIVNI"].ToString(), (string)reader["VZROK"].ToString(),

                                            (string)reader["OCENA"].ToString(), (string)reader["OPOMBA"].ToString(),

                                            (string)reader["NESKLADNOST ODPRL"].ToString(), (string)reader["KOREKCIJA PODAL"].ToString(), (string)reader["NESKLADNOST ZAPRL"].ToString(),
                                            (string)reader["NESKLADNOST VALIDIRAL"].ToString(), (string)reader["ROK ZA REŠITEV"].ToString(),

                                            (bool)reader["BIG EVENT"],

                                            (string)reader["NESKLADNOST ODPRTA"].ToString(), (string)reader["KOREKCIJA PODANA"].ToString(),
                                            (string)reader["NESKLADNOST ZAPRTA"].ToString(), (string)reader["NESKLADNOST VALIDIRANA"].ToString()
                                            ));
                    }
                }

                return output;
            }
        }
        catch (Exception)
        {
            throw;
            
        }
试试看
{
列表输出=新列表();
使用(OLEDB连接=新OLEDB连接(连接))
{
等待连接。OpenAsync();
使用(OleDbCommand命令=新的OleDbCommand(“从数据中选择*,其中[STATUS]=@STATUS;”,连接))
{
Command.Parameters.AddWithValue(“@status”,_status);
var reader=wait Command.ExecuteReaderAsync();
while(reader.Read())
{
Add(InsertID
((int)读卡器[“ID”],(string)读卡器[“STANDARD”],(string)读卡器[“NAZIV”],(string)读卡器[“POSLOVNA ENOTA”],
(字符串)读卡器[“IZVOR NESKLADNOSTI”],(字符串)读卡器[“ODDELEK”],(字符串)读卡器[“OPIS”],
(字符串)读取器[“SLIKA 1”].ToString(),
(字符串)读卡器[“SLIKA 2”].ToString(),(字符串)读卡器[“SLIKA 3”].ToString(),(字符串)读卡器[“SLIKA 4”].ToString(),
(字符串)读卡器[“SLIKA 5”].ToString(),(字符串)读卡器[“EXCEL 1”].ToString(),(字符串)读卡器[“PDF 1”].ToString(),
(字符串)读卡器[“SLIKA 6”].ToString(),(字符串)读卡器[“EXCEL 2”].ToString(),(字符串)读卡器[“PDF 2”].ToString(),
(字符串)读取器[“KOREKCIJA”].ToString(),
(字符串)读卡器[“SLIKA 7”].ToString(),(字符串)读卡器[“EXCEL 3”].ToString(),(字符串)读卡器[“PDF 3”].ToString(),
(字符串)读卡器[“KOREKTIVNI”].ToString(),(字符串)读卡器[“VZROK”].ToString(),
(字符串)读卡器[“OCENA”].ToString(),(字符串)读卡器[“OPOMBA”].ToString(),
(字符串)读卡器[“NESKLADNOST ODPRL”],(字符串)读卡器[“KOREKCIJA PODAL”],(字符串)读卡器[“NESKLADNOST ZAPRL”]。ToString(),
(字符串)读卡器[“NESKLADNOST VALIDIRAL”].ToString(),(字符串)读卡器[“ROK ZA REŠITEV”].ToString(),
(bool)阅读器[“重大事件”],
(字符串)读卡器[“NESKLADNOST ODPRTA”].ToString(),(字符串)读卡器[“KOREKCIJA PODANA”].ToString(),
(字符串)读卡器[“NESKLADNOST ZAPRTA”].ToString(),(字符串)读卡器[“NESKLADNOST VALIDIRANA”].ToString()
));
}
}
返回输出;
}
}
捕获(例外)
{
投掷;
}

致以最良好的祝愿

我认为问题出在access数据库上。根据我的经验,没有明显的原因,访问有时会失败。我花了很多时间调查访问崩溃,但没有找到解决方案。有一些事情可能会有所帮助:

  • 确保仅从单个线程使用数据库
  • 确保正确处置了所有与数据库相关的对象
  • 确保数据库不太大,数据库大小有2Gb限制。运行压缩可能会有所帮助
  • 添加更好的错误处理,捕获错误并重试该操作。如果重复出现故障,请处理并重新创建数据库连接
  • 将数据库访问移到另一个进程。这有助于错误处理,允许您在需要时重新启动整个过程

  • 我的首选解决方案是完全避免使用access。花点时间将数据移植到某个真实的数据库。

    连接调用是否可能相互干扰?启动应用程序时,您是否考虑过将后端从Access升级到更健壮的rdbms,如SQL Express或MySQL。它是否可以压缩和修复数据库?不,不是。我确实考虑过,但是各部门是不同的,所以需要很长时间才能转换成SQL。这就是我寻找快速修复的原因:)以及如何处理和重新创建数据库。我不懂那句台词?我的意思是,是的,转向sql会更好,而且我可能需要这样做。但该应用程序正在生产中,以前从未见过该漏洞。所以你的意思是,每次访问数据调用都不应该是并行的,它们应该是一个接一个的?@zigimun假设你使用的是ado.net,你应该有一个sql连接,你应该能够处理和重新创建它。@zigimun,是的,根据我的经验,如果Access不必管理并发请求,它会工作得更好。你的经历可能不同。我更新了我的问题。那么我应该在哪里处理连接呢?Mybe我应该真正切换到SQL