小编典典
使用了解GO分隔符的SQL Server管理对象(SMO)。在这里查看我的博客文章:http:_//weblogs.asp.net/jongalloway/Handling-2200_GO_2200-Separators-in-SQL-
Scripts- 2D00_ -the-easy-
way
样例代码:
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);
}
}
}
如果那不适合您,请参阅Phil
Haack的库来处理该问题:http :
//haacked.com/archive/2007/11/04/a-library-for-executing-sql-scripts-with-go-
separators -和.aspx
2020-05-19