c# - SqlDependency and SignalR ASP.NET -
c# - SqlDependency and SignalR ASP.NET -
web application asp.net not work. versions visual studio 2010 , signalr 1.0.0-rc2. debug application without problems, getnotifications event not work.
this code:
notificaciones.cs
public class notificaciones : hub { public ienumerable<sqlnotificaciones> getnotifications() { homecoming sqlwatcher.data; }
sqlwatcher.cs
public class sqlnotificaciones { public string nombre { get; set; } public string apellido { get; set; } public string fecha { get; set; } } public static class sqlwatcher { private static list<sqlnotificaciones> objloc = new list<sqlnotificaciones>(); private static sqlconnection connection = new sqlconnection(configurationmanager.connectionstrings["datos2"].connectionstring); private static sqlcommand command = new sqlcommand("select nombre, apellidop dbo.usuarios", connection); private static sqldependency dependency = new sqldependency(command); public static ienumerable<sqlnotificaciones> info { { homecoming objloc.asreadonly(); } } public static void init() { initialize(); notificaciones_info(); } private static void initialize() { sqldependency.start(configurationmanager.connectionstrings["datos2"].connectionstring); dependency.onchange += new onchangeeventhandler(dependency_onchange); } private static void dependency_onchange(object sender, sqlnotificationeventargs e) { seek { var newloc = notificaciones_info(); objloc.addrange(newloc); var context = globalhost.connectionmanager.gethubcontext<notificaciones>(); context.clients.all.update(newloc); } grab { initialize(); notificaciones_info(); } } public static ienumerable<sqlnotificaciones> notificaciones_info() { connection.open(); using (var reader = command.executereader()) homecoming reader.cast<idatarecord>() .select(x => new sqlnotificaciones() { nombre = x.getstring(0), fecha = datetime.now.tostring() }).tolist(); } }
sql.cs
<script type="text/javascript"> var hub_sql = $.connection.notificaciones; hub_sql.client.update = function (data) { alert('update'); sql_markers(data); }; sql_markers(hub_sql.server.getnotifications()); $.connection.hub.start().done(function () { hub_sql.server.getnotifications().done(function (data) { sql_markers(data); }) }) function sql_markers(datos) { (i = 0; < datos.length; i++) { alert('sql' + datos[i].apellido + 'nombre: ' + datos[i].fecha); } } </script>
i'm new in , i'm sorry english
i refer http://techbrij.com/database-change-notifications-asp-net-signalr-sqldependency , http://techbrij.com/realtime-google-maps-bing-xml-signalr-file-changes.
c# sql asp.net signalr
Comments
Post a Comment