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() 表示文件已存在 - 但事实并非如此 的相关文章

  • 在 LINQ 查询中返回不带时间的日期

    我正在编写一个查询 我想计算按日期联系我们的呼叫中心的次数 看起来很简单 但由于联系日期字段是日期时间字段 我得到了时间 因此当我按联系日期 时间 分组时 每个联系日期实例的计数为 1 所以 我想只按日期分组 而不按时间分组 下面是我用来查
  • 创建 DirectoryEntry 实例以供测试使用

    我正在尝试创建 DirectoryEntry 的实例 以便可以使用它来测试将传递 DirectoryEntry 的一些代码 然而 尽管进行了很多尝试 我还是找不到实例化 DE 并初始化它的 PropertyCollection 的方法 我有
  • 模板类的不明确多重继承

    我有一个真实的情况 可以总结为以下示例 template lt typename ListenerType gt struct Notifier void add listener ListenerType struct TimeListe
  • 如何在没有 Control.Invoke() 的情况下从后台线程修改控件属性

    最近 我们遇到了一些旧版 WinForms 应用程序 我们需要更新一些新功能 在专家测试该应用程序时 发现一些旧功能被破坏 无效的跨线程操作 现在 在您认为我是新手之前 我确实有一些 Windows 窗体应用程序的经验 我不是专家 但我认为
  • 如何在我的应用程序中使用 Windows Key

    Like Windows Key E Opens a new Explorer Window And Windows Key R Displays the Run command 如何在应用程序的 KeyDown 事件中使用 Windows
  • C# 用数组封送结构体

    假设我有一个类似于 public struct MyStruct public float a 我想用一些自定义数组大小实例化一个这样的结构 在本例中假设为 2 然后我将其封送到字节数组中 MyStruct s new MyStruct s
  • HttpClient 像浏览器一样请求

    当我通过 HttpClient 类调用网站 www livescore com 时 我总是收到错误 500 可能服务器阻止了来自 HttpClient 的请求 1 还有其他方法可以从网页获取html吗 2 如何设置标题来获取html内容 当
  • 按字典顺序对整数数组进行排序 C++

    我想按字典顺序对一个大整数数组 例如 100 万个元素 进行排序 Example input 100 21 22 99 1 927 sorted 1 100 21 22 927 99 我用最简单的方法做到了 将所有数字转换为字符串 非常昂贵
  • .Net Core / 控制台应用程序 / 配置 / XML

    我第一次尝试使用新的 ConfigurationBuilder 和选项模式进入 Net Core 库 这里有很多很好的例子 https docs asp net en latest fundamentals configuration ht
  • 为什么模板不能位于外部“C”块内?

    这是一个后续问题一个答案 https stackoverflow com questions 4866433 is it possible to typedef a pointer to extern c function type wit
  • A* 之间的差异 pA = 新 A;和 A* pA = 新 A();

    在 C 中 以下两个动态对象创建之间的确切区别是什么 A pA new A A pA new A 我做了一些测试 但似乎在这两种情况下 都调用了默认构造函数 并且仅调用了它 我正在寻找性能方面的任何差异 Thanks If A是 POD 类
  • 使用向量的 merge_sort 在少于 9 个输入的情况下效果很好

    不知何故 我使用向量实现了合并排序 问题是 它可以在少于 9 个输入的情况下正常工作 但在有 9 个或更多输入的情况下 它会执行一些我不明白的操作 如下所示 Input 5 4 3 2 1 6 5 4 3 2 1 9 8 7 6 5 4 3
  • 使用安全函数在 C 中将字符串添加到字符串

    我想将文件名复制到字符串并附加 cpt 但我无法使用安全函数 strcat s 来做到这一点 错误 字符串不是空终止的 我确实设置了 0 如何使用安全函数修复此问题 size strlen locatie size nieuw char m
  • 实体框架 - 选择特定列并返回强类型而不丢失强制类型转换

    我正在尝试做类似的事情这个帖子 https stackoverflow com questions 1094931 linq to sql how to select specific columns and return strongly
  • .NET 选项将视频文件流式传输为网络摄像头图像

    我有兴趣开发一个应用程序 它允许我从 xml 构建视频列表 包含视频标题 持续时间等 并将该列表作为我的网络摄像头流播放 这意味着 如果我要访问 ustream tv 或在实时通讯软件上激活我的网络摄像头 我的视频播放列表将注册为我的活动网
  • 检查 url 是否指向文件或页面

    我们需要以下内容 如果文件确实是文件 则从 URL 下载该文件 否则 如果它是一个页面 则什么也不做 举个简单的例子 我有以下命令来下载文件 My Computer Network DownloadFile http www wired c
  • char指针或char变量的默认值是什么[重复]

    这个问题在这里已经有答案了 下面是我尝试打印 char 变量和指针的默认值 值的代码 但无法在控制台上看到它 它是否有默认值或只是无法读取 ASCII 范围 include
  • 已过时 - OpenCV 的错误模式

    我正在使用 OpenCV 1 进行一些图像处理 并且对 cvSetErrMode 函数 它是 CxCore 的一部分 感到困惑 OpenCV 具有三种错误模式 叶 调用错误处理程序后 程序终止 Parent 程序没有终止 但错误处理程序被调
  • 如何使用 ReactiveList 以便在添加新项目时更新 UI

    我正在创建一个带有列表的 Xamarin Forms 应用程序 itemSource 是一个reactiveList 但是 向列表添加新项目不会更新 UI 这样做的正确方法是什么 列表定义 listView new ListView var
  • 如何将字符串“07:35”(HH:MM) 转换为 TimeSpan

    我想知道是否有办法将 24 小时时间格式的字符串转换为 TimeSpan 现在我有一种 旧时尚风格 string stringTime 07 35 string values stringTime Split TimeSpan ts new

随机推荐

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

    我正在开发一个与 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 结果出现