SQL Server Notifications - c#

I'm building an application which extracts data from SQL Server, the version of the server might differ from 2005 to 2012 but most important are 2008 and 2012.
If I want to listen to changes to certain tables and rows in the database, and send or fetch these changes and use them in my C# application what is the best approach?
I will not need to update any data in the database, that is the job for another already existing application.
I just want to listen to changes, or poll for changes, or anything like that.
In your experience, what is best, Service Broker? Query notifications? MSMQ? SqlDependency? Change data tracking?
Thanks in advance!

Consider using SQL Server CLR integration in combination with triggers.
For example you can protocol the changes you wish (let say in a table you create for this purpose), and you can run a watch dog process which pulls the data in constant intervals or at certain points of time up to your needs.

I think you can make use SQL Server exposed performance counters.

Related

Sync Framework questions

Okay so I have to sync data between two SQL Server Express instances and after a research I stopped at Sync Framework which I think can do the job.. but since I am pushed by time and I don't have much time to do a complete research I need to ask few questions before continuing..
Basically I will have a server database which will be cleaned once every two months and I need to have a mirror database that will contain all the records.
Does sync synchronize the records only in the destination table or it also changes the server table if there is deleted records in it?
Can I sync two SQL Server Express instances? Because I am reading the documentation and it only has SQL Server and SQL Server Express sync documentation..
Do I need to create the mirror table or sync will create it for me?
Thanks in advance :)
You can specify the sync direction, upload, download, upload and download, download and upload, its all up to you.
Yes, you can, the same SqlSyncProvider will work with SQL Express, SQL Server, Local DB and Azure SQL Database
When you provision, you will have to define the tables that needs to be sync (table, columns, etc...). you will then provision the sync, when you provision, if the tables dont exist, it will create it for you.
Sync framework is designed to work to synchronize databases, that means two way, and it includes some concept of conflict resolution. One way synchronization is called Mirroring.
No you can't. Sync Framework is an enterprise level solution. You
need to pay for it. With a SQL Server licence. Don't bother looking
elsewhere, a SQL Server license is actually pretty cheap compared to
the alternatives.
Do not know the answer.

.net windows application store data offline and store to db when there is network

I am developing a windows application for agricultural purpose. This application will be used by multiple users to maintain the data. The main issue is there won't be network connectivity on the work location. But however by end of the day they can go and synchronize if there are any option.
I just want to know how can we import and store all the data locally and update the data to database when there is network.
The options that i thought is to have SQL on every machine that runs this application. Store the data to local database when there is no network.
Having a separate button to export the local data to the centralized database when there is network.
Looks like this is complicated. Is there any better and easier option.
I prefer using c#, Visual studio.
Thanks.
You can use SQLite for storing data locally. It's fast, lightweight, and public domain.
You can use whatever the database of choice for the centralized server.
Well, this a quite broad question, as it has many options and scenarios. The questions you should ask yourself are:
Does user handle new information only or any information from any other user from the previous syncing?
Do you have to handle update conflicts?
Do you handle text information only or you have complex types and binary files?
As for the solution, the easiest way, from my point of view, would be using SQL Lite on portable devices, is a lightweight SQL client that will allow you to handle information easily. On the server you can use whatever you want, SQL Server, MySQL or any other SQL flavor you may like. Just make sure there is a connector for your portable device OS.
If you keep thinking of using SQL server on the portable device, it's a battery hogger!!!, you might want to check Microsoft Sync framework, as it provides almost all possible scenarios for handling data syncing, manage conflicts, etc.
Thanks for the answers. Please find the below solution that we implemented.
1) Installed SQL express on all the local machines
2) Used Microsoft Sync framework to sync the data. The sync is configured on demand.
Issues faced:
1) We were using geometry datatype on few tables and this was not supported by sync framework.
2) Any change in the database schema will not reflect on the client machine. We will have to delete all the system generated procedures used to track the table change and regenerate it. I am sure there will be a much better way to do this.
Cheers,
Jebli

Which one is the best method to replicate a database in SQL Server?

I was wondering which one is the best way to replicate some data of a database to another.
I have a database in one computer and this one receives some transactions. I need to send this data to another server (in the same local network) but with a modified value (I need to add 11 years to a Timestamp value).
So I was looking for some options for my case, I can develop a windows service to do this but I don't know if the sql server replication can do this for me or if there is another option like some kind of magical trigger that can do that.
I'm using SQL Server 2005 on Windows Server 2003 R2.
This link should help you:
Selecting the Appropriate Type of Replication
Quoted summary from link:
Microsoft SQL Server offers three types of replication. Each type of
replication is suited to different application requirements. Depending
on the needs of your application, you can use one or more types of
replication in a topology:
Snapshot replication
Transactional replication
Merge replication
I personally would replicate the database (transactional) and then use log shipping to update the replicated database (on your second server) with the latest data changes (from the primary server) then use a stored procedure running as a sql agent job to update the fields you need.
I personally am not a fan of triggers as you can end up having triggers activating other triggers and something that takes milliseconds to run can take seconds and if you have large volumes of data that can be painful (I manage a system that has exactly this issue - soon to be replaced thankfully)
hope this helps and if you have some follow up questions I'll be happy to help.

How can I store a lot of data locally for a program

I am current building (in C#) a fairly basic point-of-sale program for a local community in Uganda to use in tracking business at their sunflower seed press. I was thinking that I would need some sort of database (like a SQL database), but I've never set up a database before, so I'm wondering what the best way to do this is. Maybe a database isn't the best way. The program will not have internet access, so everything will have to be done locally on the machine.
I think your first step should be designing out what data you need to store. Build an Entity Relationship Model and decide what your domain model is going to be. There are many different Database Engines out there that you can use that have different features, installation requirements, etc. A database engine can be installed locally, or on a remote machine to connect to. If you're writing a C# app, you'll probably want to use the System.Data namespace. You can use plain ADO .NET, or use something like Linq To Enttiies to help create proxy classes for your data tables.
You can access a SQL database using the same API for queries / record extraction regardless of the DB Engine uses. In some caess, you may need to use a seperate library that provides an implementation (or a better one), as in the case of an Oracle Database and the Oracle Data Access Components. Right out of the gate, .NET works very well with Microsoft SQL Server, but other options would work.
The details of what database engine are not as important as defining a good set of data tables to represent your data.
Yes. If it has lots of data you have to consider using database. Whether you have internet or not, as long as you have local network, you can easily do database.
Set up a database server ( maybe sql)
Do your database and install it on the database server
Do your application and connect to your database through connection string.
You are on the right track to use a database to store data. It is pretty easy to accomplish. Your computer does not need to be connected to the internet.
SQL Server Express Edition is free with a limit of 10 gigs of data. This will probably be much, much more space than you will need.
From C#, use ADO.NET. It is very simple if you know some SQL. Code samples here.

SQL Azure Data Export Service using C#

I'm new to Azure, I want to know about how we can implement Data Export Service in C#.
Currently I am using windows azure for application development and sql azure for database. So there I want to read the data from my database and update that into some another client database based on a time interval.
I want to implement these function as a windows azure worker role. How can I do this?
Please help me...
I'm not sure what you're exactly trying to do but depending on your needs you could use one of the following options:
SQL DAC
This is more an import/export like approach (is this what you mean with "Data Export Service"?)
http://sqldacexamples.codeplex.com/wikipage?title=Import%20Export%20Service%20Client&referringTitle=Documentation
SQL Azure Data Sync
This is a synchronization solution, allowing you to use sync groups, filters, specific tables/columns, ... to synchronize data between multiple databases (both SQL Server and SQL Azure are supported).
http://msdn.microsoft.com/en-us/library/hh456371.aspx
As pointed out by Sandrino, you can use SQL Azure Data Sync. It supports the features you want to implement. Using an existing product is usually much easier than write your own.
If you want to write your own, please distinguish which data has been modified. You can take the same route as Data Sync does: Create triggers in the database. Whenever a data is inserted, updated, deleted, the trigger is invoked, and you insert some metadata in a tracking table. Then your worker role code queries the tracking table to figure out what data needs to be synched.
Best Regards,
Ming Xu.
I've written a blog post about this which uses some straightforward tooling to achieve a simple export and import, using task scheduler than worker-role which makes it pretty easy:
https://iainhunter.wordpress.com/2012/08/21/sql-azure-disaster-recovery/

Categories