Error While Using Executenonquery C#
Solution 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.
Solution 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.
Solution 3:
Install SMO using NuGet, then install VC++ 2013 Redistributables
SMO is now deployed via NuGet. The NuGet page is here.
Noted under "System Requirements" -- "Some native binaries installed with the NetFx SMO libraries also require the VC 2013 runtime to be installed; that runtime is not included in the package."
Thus, after installing SMO via NuGet, manually install the VC++ Redistributables for the architecture of your code (x86 / x64); this is the dependency that Microsoft.SqlServer.BatchParserClient.dll relies upon.
Solution 4:
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)

Post a Comment for "Error While Using Executenonquery C#"