Khi*_*Ali 5 .net c# sql smo sql-server-2008
我正在C#visual studio 2012 RC中构建应用程序.
我必须在应用程序中运行脚本.为此,我正在使用.这两个库.我的应用程序的目标.net框架是4.5.
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
Run Code Online (Sandbox Code Playgroud)
在检查天气数据库是否存在后,我编写了运行脚本的代码.
当我运行代码时会弹出一个意外的异常.我真的知道这是什么意思.你可以帮助我摆脱这个例外.
我也附加了我的代码和异常预览.
请帮助我......我已经搜索过太多了.
**Here are the Exception Details.**
Run Code Online (Sandbox Code Playgroud)
未处理System.IO.FileLoadException HResult = -2146232799消息=混合模式程序集是针对运行时的版本"v2.0.50727"构建的,如果没有其他配置信息,则无法在4.0运行时中加载.Source = mscorlib StackTrace:System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly程序集,String name,Boolean throwOnError,Boolean ignoreCase,ObjectHandleOnStack类型),位于System.Reflection.RuntimeAssembly.GetType(String name,Boolean throwOnError,Boolean ignoreCase). Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand,Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query,ExecutionTypes executionType,Int32&statementsToReverse)中的Reflection.Assembly.GetType(String name,Boolean throwOnError). ExecutionTypes executionType)在Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand)位于McFarlaneIndustriesPOSnamespace.SplashScreen.CreateDatabase()的e:\ Works\McFarlane Industries\McFarlane Industries销售点源代码\ McFarlaneIndustries\SplashScreen.cs:第139行在McFarlaneIndustriesPOSnamespace.SplashScreen.splashScreenTimer_Tick(对象发送者,EventArgs e))在e:\ Works\McFarlane Industries\McFarlane Industries销售点源代码\ McFarlaneIndustries\SplashScreen.cs:System.Windows.Form.Timer.TimerNativeWindow上的System.Windows.Forms.Timer.OnTick(EventArgs e)第159行System.Windows.Forms上的System.Windows.Forms.FornsWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)中的.WndProc(Message&m)位于System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg). System.Windows.Forms上的System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)中的Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)位于E:\ Works\McFarlane Industries\McFarlane Industries Point of S的McFarlaneIndustriesPOSnamespace.Program.Main()的System.Windows.Forms.Application.Run(Form mainForm)中的.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)ale源代码\ McFarlaneIndustries\Program.cs:在System.Runtime.Hosting.ManifestRunner的System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly,String [] args)的System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args)第19行System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext,String [] activationCustomData)中的System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()处于System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)的.Run(Boolean checkAptModel) )System.Activator.CreateInstance(ActivationContext activationContext),位于System.Threading.Thread上的System.Threading.ThreadHelper.ThreadStart_Context(对象状态)的Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()(ExecutionContext executionContext,ContextCallback回调, System.Threading.ExecutionContext.Run(ExecutionContext exec)中的对象状态,布尔值preserveSyncCtx)System.Threading.ThreadHelper.ThreadStart()中的System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)的utionContext,ContextCallback回调,Object状态,Boolean preserveSyncCtx):InnerException:
看起来你正在尝试加载.net 2版本的Microsoft.SqlServer.xxxx.dll.更新对.net4版本的引用(首选),或将以下口头禅添加到<configuration>
节点下的app.config中
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<requiredRuntime version="v4.0" />
</startup>
Run Code Online (Sandbox Code Playgroud)
允许加载.net 2程序集.详情请见此处.
归档时间: |
|
查看次数: |
2645 次 |
最近记录: |