问题
I have a problem while using ExecuteNonQuery
.
This is my code :
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);
And this is the error:
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)
I read a lot of solutions with problem but can't do anything .
Should I just install another SQL Server? I have installed SQL Server 2014 on my computer and folder with assembly looks like this:
Screenshot
What should I do to avoid this problem? I think I should have version 14.100.0.0 in my assembly folder but don't know how to update it. Maybe anyone know it?
回答1:
I had a similar issue. I have an SMO application which uses the Microsoft.SqlServer.SqlManagementObjects nuget package.
The app all runs perfectly on my p.c however when it came to deploying it and running it on our app server i was getting the error.
Could not load file or assembly 'Microsoft.SqlServer.BatchParser.dll' or one of its dependencies. The specified module could not be found.
To fix the issue I needed to build the project again targeting x86 platform.
回答2:
You should add the missing dll in your project and if you publish your project, you must put this dll in to the bin folder.
回答3:
I had faced a similar issue. In my setup, I have a WPF application which uses a class library which in turn refers the Microsoft.SqlServer.SqlManagement Objects (SMO) (version 140.17283.0
) via NuGet package.
After trying lot of things, finally figured out that in addition to the class library, the WPF application also needs to refer the SMO library via NuGet.
So I just added the SMO library via NuGet at the solution level and install it for class library as well as WPF application. Voila, it worked !!! (Looks like the Microsoft.SqlServer.BatchParserClient.dll
is not properly referenced if it is referred only in the class library which is weird but it solved the issue)
来源:https://stackoverflow.com/questions/51040998/error-while-using-executenonquery-c-sharp