尽管删除了共享,但 Access2007 OleDb 通过网络共享的连接仍然存在H

发布于 2024-10-17 20:24:57 字数 488 浏览 1 评论 0原文

我遇到了 ADO.NET / Access 2007 的一个非常奇怪的行为。

我在 PC1 上运行我的 C# 2008 程序(目标框架 .NET 2.0)。 PC1 在 PC2 上有一个网络共享(\PC2\Temp 映射为 X:) 在 Temp 中的 PC2 上有访问数据库文件 xy.mdb

该程序打开到 X:\xy.mdb 的 OleDbConnection。工作正常。

然后,当程序仍在运行时,我将共享删除到 PC2 上。 (PC1 上的 Windows 资源管理器告诉我共享 X: 丢失) 我在 PC2 上重命名了数据库文件,因此不可能有新的连接。

但程序仍然可以查询数据库! (通过 OleDbCommand.ExecuteReader() 或 ExecuteNonQuery())

有人给我解释吗? 整个数据库是否已锁定? 我可以阻止这种情况,以便在共享被删除并尝试查询不再可用的数据库时收到 OleDbException 吗?

感谢您的帮助, 拉尔夫

I've encountered a quite strange behavior of ADO.NET / Access 2007.

I run my C# 2008 program (target framework .NET 2.0) on PC1.
PC1 has a network share on PC2 (\PC2\Temp mapped as X:)
On PC2 in Temp there is the access database file xy.mdb

The program opens a OleDbConnection to X:\xy.mdb. Works fine.

Then while the program is still running I drop the share on PC2.
(Windows Explorer on PC1 tells me the share X: is lost)
I renamed the database file on PC2, so no new connection should be possible.

But the program can still query the database !
(via OleDbCommand.ExecuteReader() or ExecuteNonQuery())

Has anyone an explanation for me ?
Is the whole database latched ?
And can I prevent this so that I get an OleDbException when the share is dropped and I try to query the no longer available database ?

Thanks for any help,
Ralf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2024-10-24 20:24:57

我尝试使用以下代码和示例访问数据库重现该问题...无论我如何尝试(sahre 或映射驱动器),我总是遇到异常:

未处理的异常:
System.Data.OleDb.OleDbException:
Microsoft Jet 数据库引擎无法
查找输入表或查询
“一些垃圾”。确保它存在并且
它的名字拼写正确。

这是预期的。你应该重新审视你的环境,以达到100%。

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace AccessOverShare
{
    class Program
    {
        static void Main(string[] args)
        {
            int ct = 0;

            using(OleDbConnection oleDbConnection = new OleDbConnection())
            {
                //oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\127.0.0.1\\share\\test.mdb.";
                oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=w:\\test.mdb.";
                oleDbConnection.Open();

                using(OleDbCommand oleDbCommand = oleDbConnection.CreateCommand())
                {
                    oleDbCommand.CommandType = CommandType.Text;
                    oleDbCommand.CommandText = "select junkid, junktext from somejunk";

                    using (OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.Default))
                    {
                        ct = 0;         
                        while(oleDbDataReader.Read())
                        {
                            ct++;
                            Console.WriteLine("{0:0000}", oleDbDataReader["junkid"]);
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine(ct);
                }

                Console.WriteLine();
                Console.WriteLine();

                Console.Write("kill the share then press enter to continue");
                Console.ReadLine();

                using (OleDbCommand oleDbCommand = oleDbConnection.CreateCommand())
                {
                    oleDbCommand.CommandType = CommandType.Text;
                    oleDbCommand.CommandText = "select junkid, junktext from somejunk";

                    using (OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.Default))
                    {
                        ct = 0;
                        while (oleDbDataReader.Read())
                        {
                            ct++;
                            Console.WriteLine("{0:0000}", oleDbDataReader["junkid"]);
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine(ct);
                }
            }
        }
    }
}

I tried to reproduce the issue with the following code and a sample access db...not matter how I tried (sahre or mapped drive) i always got the exception:

Unhandled Exception:
System.Data.OleDb.OleDbException: The
Microsoft Jet database engine cannot
find the input table or query
'somejunk'. Make sure it exists and
that its name is spelled correctly.

which is expected. You should re-examine you environment to be 100%.

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace AccessOverShare
{
    class Program
    {
        static void Main(string[] args)
        {
            int ct = 0;

            using(OleDbConnection oleDbConnection = new OleDbConnection())
            {
                //oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\127.0.0.1\\share\\test.mdb.";
                oleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=w:\\test.mdb.";
                oleDbConnection.Open();

                using(OleDbCommand oleDbCommand = oleDbConnection.CreateCommand())
                {
                    oleDbCommand.CommandType = CommandType.Text;
                    oleDbCommand.CommandText = "select junkid, junktext from somejunk";

                    using (OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.Default))
                    {
                        ct = 0;         
                        while(oleDbDataReader.Read())
                        {
                            ct++;
                            Console.WriteLine("{0:0000}", oleDbDataReader["junkid"]);
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine(ct);
                }

                Console.WriteLine();
                Console.WriteLine();

                Console.Write("kill the share then press enter to continue");
                Console.ReadLine();

                using (OleDbCommand oleDbCommand = oleDbConnection.CreateCommand())
                {
                    oleDbCommand.CommandType = CommandType.Text;
                    oleDbCommand.CommandText = "select junkid, junktext from somejunk";

                    using (OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.Default))
                    {
                        ct = 0;
                        while (oleDbDataReader.Read())
                        {
                            ct++;
                            Console.WriteLine("{0:0000}", oleDbDataReader["junkid"]);
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine(ct);
                }
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文