Search code examples
c#sqlvisual-studio-2010sql-server-2008r2-express

Execute sql script on SQL server using C#


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 ?


Solution

  • 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)
    enter image description here

    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.