.net如何获取SQLServer中类似print的信息

来源:互联网 发布:mac抹掉u盘失败 编辑:程序博客网 时间:2024/06/08 12:22
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);        }    }}



1 0
原创粉丝点击