【问题标题】:connection string works fine on windows 10 but not on windows 7连接字符串在 Windows 10 上工作正常,但在 Windows 7 上不行
【发布时间】:2019-07-23 01:37:27
【问题描述】:

我已经开发了一个 wpf 应用程序,它带有到 sql server 2014 数据库的连接字符串,数据库可以在带有 sql server 2016 的 windows 10 上正常工作,但不能在带有 sql server 2014 的 windows 7 上工作!

connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Server=(localdb)\mssqllocaldb;Database=LearningSystem;attachdbfilename=|DataDirectory|Parking.mdf;integrated security=True;Connect Timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

【问题讨论】:

  • 请告诉我们您收到了哪些错误消息,这样我们就不会猜测问题可能是什么。 “它不起作用”不是有用的信息。
  • 在带有 sql server 2014 的 windows 7 上抛出异常消息:“底层提供程序在打开时失败”

标签: c# connection-string


【解决方案1】:

您正在使用在 Windows 10 计算机上创建的 localdb。您必须在Windows 7 机器上复制数据库或在那里创建另一个数据库。

服务器=(localdb)\mssqllocaldb

attachdbfilename=|DataDirectory|Parking.mdf

【讨论】:

  • 我已经复制了数据库文件。它存在于应用程序的 bin 文件夹中
  • 您必须使用CurrentDomain.SetData 显式设置|DataDirectory|,或者您可以提供完整路径来测试您的应用是否能够找到数据库。像attachdbfilename=c:\projectname/bin/Parking.mdf一样,用你的实际数据库路径替换路径
  • LocalDB 是一个单独的应用程序;它必须在 Win7 机器上,或者他必须在安装 WPF 应用程序时安装它。您也不应该使用写访问权限打开 Program Files 文件夹中的文件;如果他需要写权限,他需要将数据库文件复制到他有这种权限的地方。
猜你喜欢
  • 2019-02-09
  • 2011-07-25
  • 2011-09-11
  • 1970-01-01
  • 2022-08-22
  • 2012-07-04
  • 2021-10-30
  • 1970-01-01
  • 2020-05-03
相关资源
最近更新 更多