Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Handle on SQL Server Message Output [duplicate]

When executing scripts in SQL Server Management Studio, messages are often generated that display in the message window. For example when running a backup of a database:

10 percent processed.

20 percent processed.

Etc...

Processed 1722608 pages for database 'Sample', file 'Sampe' on file 1.

100 percent processed.

Processed 1 pages for database 'Sample', file 'Sample_Log' on file 1.

BACKUP DATABASE successfully processed 1722609 pages in 202.985 seconds (66.299 MB/sec).

I would like to be able to display these message in a C# application that is running SQL scripts against a database. However, I cannot figure out how to get a handle on the message output from SQL as it is generated. Does anybody know how to do this? It doesn't matter to me which connection framework I have to use. I'm relatively comfortable with LINQ, NHibernate, Entity Framework, ADO.Net, Enterprise Library, and am happy to learn new ones.

like image 658
bopapa_1979 Avatar asked Oct 05 '11 15:10

bopapa_1979


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C in C?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'. So ++ being the increment operator, C has an incremented version called as “C++”.

Why is C language popular?

It is fast The programs that you write in C compile and execute much faster than those written in other languages. This is because it does not have garbage collection and other such additional processing overheads. Hence, the language is faster as compared to most other programming languages.

Why is C called a mid level programming language?

C has the features of both assembly level languages i.e low-level languages and higher level languages. So that's why C is generally called as a middle-level Language. The user uses C language for writing an operating system and generates menu driven customer billing system.


1 Answers

The SqlConnection.InfoMessage event occurs when SQL Servers returns a warning or informational message. This website shows a possible implementation.

like image 127
Sascha Hennig Avatar answered Oct 28 '22 05:10

Sascha Hennig