我在 C# 中使用 SMO 来运行 SQL 脚本。我需要将文件的结果输出到文本文件中。
使用命令行运行查询时,我可以使用“-o [输出文件]”参数获得所需的结果。有没有办法使用 SMO 对象执行相同的操作?
目前我的代码只是将一个 sql 脚本发送到服务器:
// Read the sql file
string script = sqlFile.OpenText().ReadToEnd();
// Create a new sql connection, and parse this into a server connection.
SqlConnection sqlConnection = new SqlConnection(connectionString);
Server server = new Server(new ServerConnection(sqlConnection));
// Run the sql command.
server.ConnectionContext.ExecuteNonQuery(script);
任何帮助将非常感激!