c# - 使用 ExecuteNonQuery c# 时出错

标签 c# sql executenonquery

我在使用 ExecuteNonQuery 时遇到问题。

这是我的代码:

var connString = @"Data Source=serwer01;Initial Catalog=PolsatCyfrowy;Integrated Security=True";

FileInfo file = new FileInfo("C:\\Users\\azbudniewek\\source\\repos\\UM2 V2\\UM2 V2\\scripts.sql");
string script = file.OpenText().ReadToEnd();

SqlConnection conn = new SqlConnection(connString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);

这是错误:

System.IO.FileNotFoundException: The file or set 'Microsoft.SqlServer.BatchParser, version = 14.100.0.0, Culture = neutral, PublicKeyToken = 89845dcd8080cc91' or one of its company can not be loaded. The file can not be downloaded.
File name: 'Microsoft.SqlServer.BatchParser, version = 14.100.0.0, Culture = neutral, PublicKeyToken = 89845dcd8080cc91'

in System.Reflection.RuntimeAssembly.GetType (RuntimeAssembly set, string name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack)
in System.Reflection.RuntimeAssembly.GetType (string name, Boolean throwOnError, Boolean ignoreCase)

我阅读了很多有问题的解决方案,但无能为力。

我应该再安装一个 SQL Server 吗?我已经在我的计算机上安装了 SQL Server 2014,带有程序集的文件夹如下所示:

Screenshot

我应该怎么做才能避免这个问题?我想我的程序集文件夹中应该有版本 14.100.0.0,但不知道如何更新它。也许有人知道?

最佳答案

我遇到了类似的问题。我有一个使用 Microsoft.SqlServer.SqlManagementObjects nuget 包的 SMO 应用程序。

该应用程序在我的电脑上运行完美,但在部署它并在我们的应用程序服务器上运行时,我遇到了错误。

无法加载文件或程序集“Microsoft.SqlServer.BatchParser.dll”或其依赖项之一。找不到指定的模块。

为了解决这个问题,我需要针对 x86 平台再次构建项目。

关于c# - 使用 ExecuteNonQuery c# 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51040998/

相关文章:

c# - 当我们没有该 dll 的源代码时,如何在 Visual Studio 中调试非托管 dll?

c# - 以下哪种并行化异步方法的方法最合适?

sql - 使用 SSRS 报告将 csv 列表传入 SQL 数据集的参数值

sql - 运行示例代码段时突然 “Must declare the scalar variable”

.net - 为什么 "Non"中的 "ExecuteNonQuery"?

c# - 如何向数据库中插入数据? - 用户定义的类

c# - WebAPI 和 ILMerge(又名自托管单个 exe)

c# - EntityDataSource 和 Entity Framework 6

mysql - 查找登录同一辆车的用户