How to user SQLDependency in Xamarin Cross Platform Project ?

I want to use sqldependency in my cross platform project. how can i ? or any other method through which i can notify changes in sql data. I have bounded listview with sql data and want to refresh it only when backend data changes..



  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    It looks like that should be available in Xamarin.Android and Xamarin.iOS.

    Did you try something like:

    System.Data.SqlClient.SqlDependency sqlDependency = new System.Data.SqlClient.SqlDependency();
    sqlDependency.OnChange += Dependency_OnChange;
    void Dependency_OnChange(object sender, System.Data.SqlClient.SqlNotificationEventArgs e)
         // handle event 

    You do realize that as a general rule, it is best not to access an SQL database directly from a mobile app because then your SQL database has to be available to every possible ip address that a mobile device running your app may possibly use, which can leave your SQL database open to attack. Generally a web API is created that your mobile app can access and that web service accesses the SQL database.

  • rajeshmalamrajeshmalam Member ✭✭

    Thanks sir for ur prompt reply.. I am accessing sql from web service itself. The issue is that when i user sqldependency in my xamarin project it gives me error "system could not load". however i can use other classes of it like sqlconnection and sqlcommand but not sqldependency. My requirement is ..I have made one void to fill up the list with my data and i want to refresh it when my sql data changes without setting up any timer. That's y i want to implement sqldependency over it..

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    If you are accessing sql from a web service, isn't that where you should set up the sql dependency? Your mobile app is not connecting to the sql database, so how can you do the dependency in your mobile app? Sorry, perhaps I am naive on this subject, but this is not making sense to me.

    I would think you want to set up the dependency on your web service and then use SignalR (assuming your web service is ASP.NET) in order to get updates when the sql database changes. Intro to SignalR:

Sign In or Register to comment.