Použijte SQL Server Management Objects (SMO), který rozumí oddělovačům GO. Viz můj příspěvek na blogu zde:http://weblogs.asp.net/jongalloway/Handling-_2200_GO_2200_-Separators-in-SQL-Scripts-2D00 -snadná cesta
Ukázkový kód:
public static void Main()
{
string scriptDirectory = "c:\\temp\\sqltest\\";
string sqlConnectionString = "Integrated Security=SSPI;" +
"Persist Security Info=True;Initial Catalog=Northwind;Data Source=(local)";
DirectoryInfo di = new DirectoryInfo(scriptDirectory);
FileInfo[] rgFiles = di.GetFiles("*.sql");
foreach (FileInfo fi in rgFiles)
{
FileInfo fileInfo = new FileInfo(fi.FullName);
string script = fileInfo.OpenText().ReadToEnd();
using (SqlConnection connection = new SqlConnection(sqlConnectionString))
{
Server server = new Server(new ServerConnection(connection));
server.ConnectionContext.ExecuteNonQuery(script);
}
}
}
Pokud to pro vás nebude fungovat, podívejte se na knihovnu Phila Haacka, která to řeší:http://haacked.com/archive/2007/11/04/a-library-for-executing-sql-scripts-with-go-separators -a.aspx