从运行应用程序在C#中使用SMO库.sql文件 [英] Run .sql file from Application in C# using SMO library

查看:512
本文介绍了从运行应用程序在C#中使用SMO库.sql文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立在C#中的Visual Studio 2012 RC的应用程序。

I am building an application in C# visual studio 2012 RC.

我要运行的应用程序中的脚本。为此我使用。 这两个库。 我的应用程序的目标。NET框架4.5。

I have to run the scripts within the application. for this i am using. These two libraries. My application's target .net framework is 4.5.

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

我写了code,以检查气象数据库的存在与否之后运行的脚本。

I wrote the code to run the scripts after checking weather database exists or not.

当我运行code到意外的异常弹出。我真的知道是什么意思。能否请你帮我,为了摆脱这种异常。

When i run the code an unexpected exception pops up. i really know what does it mean. Could you please help me in order to get rid of this exception.

我附上了我的code和异常preVIEW也。

I am attaching the my code and exception preview also.

请帮我...我用Google搜索太多了。

Please HELP ME... I have googled too much already.

**Here are the Exception Details.**

System.IO.FileLoadException是未处理   HResult的= -2146232799   消息=混合模式组件构建针对运行时的版本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(查询字符串,ExecutionTypes executionType,的Int32和放大器; statementsToReverse)        在Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(字符串的SqlCommand,ExecutionTypes executionType)        在Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(字符串的SqlCommand)        在McFarlaneIndustriesPOSnamespace.SplashScreen.CreateDatabase()在E:\售来源$ C ​​$作品\麦克法兰工业\麦克法兰工业c点\ McFarlaneIndustries \ SplashScreen.cs:行139        在McFarlaneIndustriesPOSnamespace.SplashScreen.splashScreenTimer_Tick(对象发件人,EventArgs e)在E:\售来源$ C ​​$作品\麦克法兰工业\麦克法兰工业c点\ McFarlaneIndustries \ SplashScreen.cs:行159        在System.Windows.Forms.Timer.OnTick(EventArgs的五)        在System.Windows.Forms.Timer.TimerNativeWindow.WndProc(消息&安培;米)        在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的的HWND,味精的Int32,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(表格的MainForm)        在McFarlaneIndustriesPOSnamespace.Program.Main()在E:\的销售来源$ C ​​$ C厂\麦克法兰工业\麦克法兰工业点\ McFarlaneIndustries \的Program.cs:行19        在System.AppDomain._nExecuteAssembly(RuntimeAssembly组装,字串[] args)        在System.AppDomain.nExecuteAssembly(RuntimeAssembly组装,字串[] args)        在System.Runtime.Hosting.ManifestRunner.Run(布尔checkAptModel)        在System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()        在System.Runtime.Hosting.ApplicationActivator.CreateInstance(Activati​​onContext activati​​onContext,字符串[] activati​​onCustomData)        在System.Runtime.Hosting.ApplicationActivator.CreateInstance(Activati​​onContext activati​​onContext)        在System.Activator.CreateInstance(Activati​​onContext activati​​onContext)        在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()        在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)        在System.Threading.ExecutionContext.RunInternal(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态,布尔preserveSyncCtx)        在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态,布尔preserveSyncCtx)        在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象的状态)        在System.Threading.ThreadHelper.ThreadStart()   的InnerException:

System.IO.FileLoadException was unhandled HResult=-2146232799 Message=Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Source=mscorlib StackTrace: at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at System.Reflection.Assembly.GetType(String name, Boolean throwOnError) at Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query, ExecutionTypes executionType, Int32& statementsToReverse) at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType) at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand) at McFarlaneIndustriesPOSnamespace.SplashScreen.CreateDatabase() in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\SplashScreen.cs:line 139 at McFarlaneIndustriesPOSnamespace.SplashScreen.splashScreenTimer_Tick(Object sender, EventArgs e) in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\SplashScreen.cs:line 159 at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at McFarlaneIndustriesPOSnamespace.Program.Main() in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

推荐答案

它看起来像你试图加载.NET 2.0版本Microsoft.SqlServer.xxxx.dll的。更新您提到一个.NET4版本(preferable),或添加下面的口头禅你的app.config下的<结构> 节点

It looks like you're trying to load .net 2 version of Microsoft.SqlServer.xxxx.dll. Update your references to a .net4 version (preferable), or add the following mantra to your app.config under the <configuration> node

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  <requiredRuntime version="v4.0" />
</startup>

要允许加载.NET 2集。请参见查看详情的。

to allow loading of .net 2 assemblies. See here for details.

这篇关于从运行应用程序在C#中使用SMO库.sql文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆