.net如何获取SQLServer中类似print的信息
发布时间:2020-12-12 13:09:00 所属栏目:MsSql教程 来源:网络整理
导读: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 connectionSt
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); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |