我正在 C# Visual Studio 2012 RC 中构建一个应用程序。
我必须在应用程序中运行脚本。为此我正在使用。
这两个库。
我的应用程序的目标 .net 框架是 4.5。
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
我编写了代码来在检查天气数据库是否存在后运行脚本。
当我运行代码时,会弹出意外的异常。我真的知道这意味着什么。您能帮我摆脱这个异常吗?
我还附上了我的代码和异常预览。
请帮助我...我已经用谷歌搜索了太多了。
**Here are the Exception Details.**
System.IO.FileLoadException 未处理
HResult=-2146232799
Message=混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有附加配置信息,则无法在 4.0 运行时中加载。
来源=mscorlib
堆栈跟踪:
在 System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly 程序集、字符串名称、布尔型 throwOnError、布尔型ignoreCase、ObjectHandleOnStack 类型)
在 System.Reflection.RuntimeAssembly.GetType(字符串名称,布尔值 throwOnError,布尔值ignoreCase)
在 System.Reflection.Assembly.GetType(字符串名称,布尔值 throwOnError)
在 Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(字符串查询、ExecutionTypesexecutionType、Int32& statementsToReverse)
在Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(字符串sqlCommand,ExecutionTypes执行类型)
在 Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(字符串 sqlCommand)
位于 e:\Works\McFarlane Industries\McFarlane Industries 销售点源代码\McFarlaneIndustries\SplashScreen.cs 中的 McFarlaneIndustriesPOSnamespace.SplashScreen.CreateDatabase():第 139 行
位于 e:\Works\McFarlane Industries\McFarlane Industries 销售点源代码\McFarlaneIndustries\SplashScreen.cs 中的 McFarlaneIndustriesPOSnamespace.SplashScreen.splashScreenTimer_Tick(Object sender, EventArgs e):第 159 行
在 System.Windows.Forms.Timer.OnTick(EventArgs e)
在 System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32原因,Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 原因,ApplicationContext 上下文)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 原因,ApplicationContext 上下文)
在 System.Windows.Forms.Application.Run(Form mainForm)
位于 e:\Works\McFarlane Industries\McFarlane Industries 销售点源代码\McFarlaneIndustries\Program.cs 中的 McFarlaneIndustriesPOSnamespace.Program.Main():第 19 行
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,String[] args)
在 System.AppDomain.nExecuteAssembly(RuntimeAssembly 程序集,String[] args)
在 System.Runtime.Hosting.ManifestRunner.Run(布尔 checkAptModel)
在 System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
在 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContextactivationContext,String[]activationCustomData)
在System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContextactivationContext)
在 System.Activator.CreateInstance(ActivationContext 激活上下文)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallback回调,对象状态,布尔保留SyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback 回调,对象状态,布尔保留SyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback 回调,对象状态)
在 System.Threading.ThreadHelper.ThreadStart()
内部异常:
您似乎正在尝试加载 .net 2 版本的 Microsoft.SqlServer.xxxx.dll。将您的引用更新为 .net4 版本(首选),或将以下口头禅添加到您的 app.config 下<configuration>
node
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<requiredRuntime version="v4.0" />
</startup>
允许加载 .net 2 程序集。看此处了解详细信息 http://connect.microsoft.com/SQLServer/feedback/details/643811/net-4-0-compatible-smo.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)