Capturing a print output stored procedure in .NET (another model!)

Basically, this question with a difference ...

Is it possible to capture print output from a TSQL stored procedure in .NET using the Entity Framework?

The solution in another question does not work for me. It works with the connection type from System.Data.SqlClient, but I use one of System.Data.EntityClient, which does not have InfoMessage . (Of course, I could just create an SQL connection based on the Entity connection settings, but I prefer to do it directly.)

+6
c # stored-procedures entity-framework
source share
2 answers

Actually, this is true, but since EF is not specific to SQL Server, you must specify it:

var sqlConn = (SqlConnection)Context.Connection.StoreConnection; 
+10
source share

Just to show people a complete working example from Craig's answer and Wim's answer:

 var entityConnection = (EntityConnection)Context.Connection; var sqlConnection = (SqlConnection)entityConnecion.StoreConnection; sqlConnection.InfoMessage += (s,a) => Debug.WriteLine(a.Message); 

Steve

+8
source share

All Articles