DataContext.CreateDatabase() 表示文件已存在 - 但事实并非如此

2024-05-11

这可能是 Windows 7 问题,但调用

using (var context = new DataClassesDataContext())
{
    if (!context.DatabaseExists())
    {
        context.CreateDatabase();
    }
}

结果出现以下错误:

System.Data.SqlClient.SqlException 是 未处理的消息=数据库 'C:\Temp\SmallBusinessManager.mdf' 已经存在。选择不同的 数据库名称。来源=.Net SqlClient 数据提供者错误代码=-2146232060 类别=16 行号=1 号码=1801 程序=“”
服务器=\.\pipe\952FCA9D-B4B6-4C\tsql\query 状态=3 堆栈跟踪: 在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔中断连接) 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException 异常,布尔中断连接) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior、SqlCommand cmdHandler、 SqlDataReader数据流, 批量复制简单结果集 批量复制处理程序、TdsParserStateObject 状态对象) 在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(字符串 方法名称,布尔异步) 在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult 结果,字符串方法名称,布尔值 发送到管道) 在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在 System.Data.Linq.SqlClient.SqlProvider.ExecuteCommand(字符串 命令) 在 System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.CreateDatabase() 在 System.Data.Linq.DataContext.CreateDatabase()

不过我已经删除了数据库文件。可能是什么原因造成的?文件真的存在但不知何故看不见吗?和路口有关系吗?


跟踪错误

所以我也一直在尝试创建一个基于文件的数据库(名为C:\y\bjdatamig\IntermediateData.mdf)通过运行DataContext.CreateDatabase()命令并得到相同的错误。

我在 Vista SP2 上使用 SQLExpress 2008 和 VS2008,并使用 Process Monitor 作为Josh https://stackoverflow.com/users/81769建议在他的回答 https://stackoverflow.com/questions/2796013/datacontext-createdatabase-says-file-already-exists-but-it-doesnt/2796022#2796022这里。这让我看到 SQL Server 正在写入其 error.log 文件,该文件又显示了以下相关信息块(此处提供了全部信息,以防其他人在消息中看到有用的信息):

2010-06-23 17:04:10.50 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2010-06-23 17:04:10.50 Server      Detected 2 CPUs. This is an informational message; no user action is required.
2010-06-23 17:04:10.55 Server      Perfmon counters for resource governor pools and groups failed to initialize and are disabled.
2010-06-23 17:04:10.55 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2010-06-23 17:04:10.65 Server      Node configuration: node 0: CPU mask: 0x00000003 Active CPU mask: 0x00000003. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2010-06-23 17:04:10.69 spid7s      Starting up database 'master'.
2010-06-23 17:04:10.79 spid7s      1 transactions rolled forward in database 'master' (1). This is an informational message only. No user action is required.
2010-06-23 17:04:10.91 spid7s      0 transactions rolled back in database 'master' (1). This is an informational message only. No user action is required.
2010-06-23 17:04:10.91 spid7s      Recovery is writing a checkpoint in database 'master' (1). This is an informational message only. No user action is required.
2010-06-23 17:04:11.12 spid7s      Error: 5598, Severity: 16, State: 2.
2010-06-23 17:04:11.12 spid7s      FILESTREAM feature is not supported on user instances.
2010-06-23 17:04:11.12 spid7s      FILESTREAM: effective level = 0, configured level = 0, file system access share name = 'SQLEXPRESS'.
2010-06-23 17:04:11.25 spid7s      SQL Trace ID 1 was started by login "sa".
2010-06-23 17:04:11.31 spid7s      Starting up database 'mssqlsystemresource'.
2010-06-23 17:04:11.33 spid7s      The resource database build version is 10.00.2531. This is an informational message only. No user action is required.
2010-06-23 17:04:11.90 spid9s      Starting up database 'model'.
2010-06-23 17:04:11.91 Server      Server local connection provider is ready to accept connection on [ \\.\pipe\95B6C915-3DB7-46\tsql\query ].
2010-06-23 17:04:11.94 Server      Dedicated administrator connection support was not started because it is disabled on this edition of SQL Server. If you want to use a dedicated administrator connection, restart SQL Server using the trace flag 7806. This is an informational message only. No user action is required.
2010-06-23 17:04:11.95 spid7s      Server name is 'JOHN-W500\95B6C915-3DB7-46'. This is an informational message only. No user action is required.
2010-06-23 17:04:12.22 spid7s      Starting up database 'msdb'.
2010-06-23 17:04:12.27 Server      The SQL Server Network Interface library could not register the Service Principal Name (SPN) for the SQL Server service. Error: 0x5, state: 4. Failure to register an SPN may cause integrated authentication to fall back to NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies.
2010-06-23 17:04:12.27 Server      SQL Server is now ready for client connections. This is an informational message; no user action is required.
2010-06-23 17:04:12.60 spid9s      Clearing tempdb database.
2010-06-23 17:04:15.49 spid9s      Starting up database 'tempdb'.
2010-06-23 17:04:16.27 spid12s     The Service Broker protocol transport is disabled or not configured.
2010-06-23 17:04:16.27 spid12s     The Database Mirroring protocol transport is disabled or not configured.
2010-06-23 17:04:16.36 spid12s     Service Broker manager has started.
2010-06-23 17:04:16.37 spid7s      Recovery is complete. This is an informational message only. No user action is required.
2010-06-23 17:04:17.84 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 17:04:17.84 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 17:31:29.89 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 17:31:29.89 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 17:33:07.09 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 17:33:07.09 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 17:49:53.53 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 17:49:53.53 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 18:01:02.74 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 18:01:02.74 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 18:02:50.92 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 18:02:50.92 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 18:04:06.31 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 18:04:06.31 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
2010-06-23 18:06:41.22 Logon       Error: 15350, Severity: 16, State: 1.
2010-06-23 18:06:41.22 Logon       An attempt to attach an auto-named database for file C:\y\bjdatamig\IntermediateData.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

我的 SQL 日志文件位于:

C:\Users\John\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS\error.log

重要的是,对于我的情况,它表明用户实例不支持“功能”,似乎与流式传输文件有关,当然创建数据库正在尝试写入文件系统...

2010-06-23 17:04:11.12 spid7s      Error: 5598, Severity: 16, State: 2.
2010-06-23 17:04:11.12 spid7s      FILESTREAM feature is not supported on user instances.

...我的 APP.CONFIG 中的连接字符串也指定了一个“用户实例”...

<add connectionString="Data Source=JOHN-W500\SQLEXPRESS;AttachDbFilename=C:\y\bjdatamig\IntermediateData.mdf;Integrated Security=True;User Instance=True" name="IntermediateData" providerName="System.Data.SqlClient" />

Solution

我改变了我的连接字符串

;Integrated Security=True;

to

;Integrated Security=False;

数据库是在文件系统上创建的。

为什么我不必更改“用户实例”选项?嗯,我不确定。事实上,在我开始出现此错误之前,代码就可以工作,但我已经一个月没有尝试过 - 我的猜测可能是系统更新或 SQL Server 更改导致了它。因此,尽管已解决,但它仍然有点神秘。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DataContext.CreateDatabase() 表示文件已存在 - 但事实并非如此 的相关文章

随机推荐

  • 如何正确关闭保存文件句柄

    我正在开发一个与 USB 设备通信的 C 项目 我打开连接 DllImport Kernel32 dll SetLastError true static extern Microsoft Win32 SafeHandles SafeFil
  • grunt-contrib-watch 导致超出最大调用堆栈大小

    当我执行 clean 任务 grunt clean 时 一切都按预期工作 但是当我运行 watch 任务 grunt test 时 出现以下错误 util js 35 var str String f replace formatRegEx
  • cron 爬虫使用 Ruby 中的 Google API 将数据插入 Google 电子表格的授权问题

    我的项目是每天早上 9 00 抓取某些网络数据并将它们放入我的 Google 电子表格中 并且它必须获得读取和写入某些内容的授权 这就是为什么下面的代码位于顶部 Google API CLIENT ID blah blah CLIENT S
  • Joda Time 类没有任何构造函数...为什么?我做错了什么?

    显然 Eclipse 上的 Scala 试图让我相信DateTime Period DateMidnightJoda Time 中的许多其他类没有任何构造函数 考虑到它们的文档显示了构造函数和许多方法 这很奇怪 我唯一可以访问的是静态方法
  • Flexbox 中的图像高度在 IE 中不起作用

    我有一个 Flex 行 其中包含 5 个 Flex 单元格 其中包含一个应该在中间对齐的图像 它在 Chrome 和 Firefox 中完美运行 但在 IE 中却不行 它没有得到好的比例 换句话说 height auto当图像位于 Flex
  • 取消并重新启动 CountDownTimer 问题

    您好 我在使用 CountDownTimer 函数时遇到问题 首先我可以用 counter cancel 让它停止倒计时 然后我将 milliUntilFinished 值存储在 countercur 中 然后我使用存储的 counterc
  • 2015 年重新审视 Ember Handling 401

    我可以在 Ember Ember Data 中找到大量询问 回答如何从 Rails 后端处理 401 的老问题 许多 如果不是全部的话 在这一点上似乎已经过时了 我已经尝试了我能找到的一切 Ember 数据处理 401 https stac
  • 如何在WP7 WebBrowser控件中注入Javascript?

    我可以通过此链接将 JavaScript 注入到 C Windows 窗体中的 WebBrowser 控件中 如何在WebBrowser控件中注入JavaScript https stackoverflow com questions 15
  • 具有非常大的数字的除法

    我只是想知道在处理大数字时有哪些不同的除法策略 我所说的大数字是指 50 位数字 例如 9237639100273856744937827364095876289200667937278 82637448262718273966299344
  • Xamarin Forms 框架阴影设计

    我有一个带有列表的 Xamarin 内容页面 对于 ListItems 我想要类似于 Android 中的卡片视图的东西 根据我发现可以通过框架来完成 我有这个代码
  • hadoop中reducer的数量

    我正在学习hadoop 我发现减速器的数量非常令人困惑 1 reducer的数量与partition的数量相同 2 reducer 的数量是 0 95 或 1 75 乘以 节点数 每个节点的最大容器数 3 减速机数量设定为mapred re
  • Windows 上的 wchar_t 和 char16_t 是一样的吗?

    我有一个实例std u16string 我可以通过它吗c str 到一个 Win32 API 它期望LPCWSTR 没有任何类型的转换 例如 我可以安全地这样做吗 auto u16s std u16string u Hello SetWin
  • 我想在后端验证来自 golang 前端的时区

    前端在注册期间发送时区以及其他用户详细信息 我需要在时区上放置一个验证器来进行 api 测试 时区数据的格式为 GMT 10 00 Hawaii GMT 08 00 Pacific Time US amp Canada 我所做的是定义数组中
  • 如何从 OpenCover 报告中排除类别

    在使用 OpenCover 为 MSTest 套件生成覆盖率报告 然后使用 ReportGenerator 生成 HTML 报告 时 我尝试排除框架生成的类 特别是 通过服务引用在项目的命名空间下生成的类 我用来生成 XML 文件的命令如下
  • jwt.io 上的“秘密 Base64 编码”是什么意思以及如何使用 `openssl dgst` 模拟它

    我尝试从 jwt io 获得相同的输出openssl 只要我这样做not mark 秘密base64编码 我可以把签名之前的部分 运行它 echo n pasted data from jwt io openssl dgst binary
  • 如何从网页启动 Windows 应用程序?

    我们有一个公司内部网 并且权力机构认为拥有一组代表大多数代表使用的应用程序 Outlook Excel 少数其他应用程序 的图标 链接会很好 这个想法是 如果安装了应用程序 单击链接 图标将在客户端计算机上启动该应用程序 有人曾经有过这样的
  • Android 浏览器是否在 touchStart 上锁定 DOM?

    我正在尝试构建一个包含 5 个块的菜单 用户可以在其中旋转 您可以在这里查看演示 http m iijax com menu php http m iijax com menu php 在 iPhone 上运行良好 有时有点迟缓 但这不是重
  • 用于移动 Web 应用程序的带有图表的框架

    我正在开发一个移动网络应用程序 我需要在饼图中表示一些数据 但是我没有找到任何好的框架来提供良好的选择并在移动设备上正常工作 我想知道一些框架 免费 这可以帮助我 如果您能给出一些基础示例 我会感到惊讶 我正在考虑使用 ajax 技术来显示
  • 如何在 macOS 上的 SwiftUI 中设置拖动图像

    我正在尝试更改 GridView 的默认拖放预览图像 该图像似乎包含网格中的所有可见项目 据我了解 我应该能够设置NSItemProvider previewImageHandler块来自定义所使用的图像 我似乎找不到任何关于返回自定义图像
  • DataContext.CreateDatabase() 表示文件已存在 - 但事实并非如此

    这可能是 Windows 7 问题 但调用 using var context new DataClassesDataContext if context DatabaseExists context CreateDatabase 结果出现