且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#在SQL Server上执行SQL脚本

更新时间:2023-01-23 10:02:55

您可能需要SQL Server随附的SDK附带的程序集. 请确保在安装SQL Server时已安装SDK . >

(截取自Google随机图片的屏幕截图,突出显示的项目是您所需要的)

默认情况下,它们位于与C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies相似的路径中.版本号可能与已安装的SQL Server版本不同.

SQL Server 2008 R2 Express, .Net Framework 4.0, Visual Studio 2010

I'm trying to execute a SQL script from a command prompt application. I found a sample
code and trying to implement the same. But the following using statements are not recognized.

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

Am I missing any assembly reference ?

You likely are, you need the assemblies that are included with the SDK that comes with SQL server. Be sure you installed the SDK when you installed SQL server.

(screenshot taken from a random google image search, the highlighted item is what you need)

By default they are located at a path similar to C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies The version number may be different for the version of SQL server you have installed.