using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.sqlClient; using System.Data; using System.Text.RegularExpressions; namespace ConsoleApplication16 { class Program { static string connectionString = "data source=(local),2014;initial catalog=AdventureWorks2014;user id=?;password=?;"; static void Main(string[] args) { using (sqlConnection sqlcon = new sqlConnection(connectionString)) { sqlcon.open(); sqlcon.InfoMessage += new sqlInfoMessageEventHandler(OnReceivingInfoMessage); /* 查询某个表上的索引碎片的详细信息 */ sqlCommand cmd = new sqlCommand("print 'Begin……'; DBCC SHOWCONTIG('[dbo].[ErrorLog]'); print 'End'",sqlcon); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } Console.Read(); } private static void OnReceivingInfoMessage(object sender,sqlInfoMessageEventArgs e) { Console.WriteLine(e.Message); } } }