I'm using Ado.Net Data Entity Model to add records to a local Sql Compact database every second. I want to sync it to a database on the server.
Can you point me in the right direction please?
do you have to write to both databases? how about setting up a replication between the databases?
http://msdn.microsoft.com/en-us/library/ms171850.aspx
The Microsoft Sync Framework was designed for this scenario.
We are using Sync framework in our projects . we have implemented sync in sql server and PG SQL , It works reasonably well for us . In addition we have implemented batching too.
To start with refer this documentation and sample code
http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=4835
This will show you how to synchronize data between multiple sql server databases. You can also customize the 'increments' stored procedures to take custom parameters and filter data based on these parameters (for instance people the client-user is planning to visit).
I will also suggest that you use a reflector to decompile Sync framework code in case you see wierd errors - sometimes it is not possible to figure out where the error is till you see the exception getting caught in the framework code. Redgate works perfectly for me!
Let me know if you need more help!
Related
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.
I am developing a Microsoft Kinect game (for Windows) using C# and I need a local database to store information about players and their progress as well as more detailed information on their points and accuracy. I have never used a database within a Windows application and I was looking for some advice on how to do so. I have been trying to use SQL Server because it lets me create a database within Visual Studio. I have been unable to find many resources on how to interact with the database from within the C# application.
I really know very little about SQL Server so I do not know if it is the right choice for what I need. Does anyone have a suggestion for what sort of database system to use? Can you point me in the direction of some good resources/examples on how to do what I need to do?
Thanks so much!
Edit: I should also mention that I do have experience working with SQL.
There are other, more portable, solutions such as SQLite and SQL Server Compact Edition which do not require a separate server installation and are more easily accessed and distributed from within a standalone desktop application.
The usage can be largely compared to an external SQL server and/or Linq to SQL so the actual implementation should not be that hard.
Some interesting links:
How to: Deploy a SQL Server Compact 4.0 Database with an Application
An Introduction to SQL Server Compact Edition
As mentioned in another comment, a simple serialized XML file might also be enough for your use. It's fast, easy and if you don't need to perform any actual database operations but simply save and load everything then it might be more efficient.
Look into using a SQLDatasource and relevant tutorials. This will give you an easy way to get up and running without an intimate knowledge of SQL. Once you have the datasource setup and 'bound' to your database, you can use this to connect your controls (grids,labels,textboxes ect.) to it.
Check this out:
http://www.youtube.com/watch?v=w34BDhDPEEQ
You don't want the fully fledged SQL Server. SQL Server Compact Edition is more appropriate, or there's also SQLite for a non-Microsoft option.
The easiest way to interact with a database from C# is Entity Framework, which ships with .NET 4.5 or is downloadable as a nuget package for .NET 3.5 and .NET 4.
A different, non-relational-database option would be DB4O.
You could use Entity Framework
var player = db.Players.Where(x => x.playerId = id);
var points = player.points;
points =+ 100;
db.SaveChanges();
You could also write CRUD operations against the tables if you don't want to use an ORM
Basicly you will have to make a database with a table, using the GUI of Visual Studio.
Then where necessary in the code, you will have to create a connection with the database using a connectionstring. Then you will have to insert an SQL command using the SQLCommand class and execute it. This requires some knowledge about the SQL syntax, but just search what kind of command you want specifically now and in time you will get the hang of it. Don't forget to close the connection to the database when you are ready with writing or reading data.
I hope this gives the main idea.
Edit: Oh and for this kind of database SQL Server Compact will be enough.
I need to get changes from several tabases into my 1 database, so I guess sql notifier will be best way.
I found interesting application: http://www.codeproject.com/Articles/144344/Query-Notification-using-SqlDependency-and-SqlCach
that works, but only in one database.
Im not asking for full-solution, maybe just some of you work with project like that, and know how can I use sqlnotifier to read data from different databases?
Depending on what information you want to track, the SQL Server 2008 developer certification suggests using either CDC (change data capture) or CT (change tracking).
Look here for the details.
You may also consider using the auditing feature built-in.
As an alternative you might want to investigate Microsoft Sync Framework to implement what you want, since it looks like you really need a sync solution.
Using this you could sync between two or multiple sql server databases. And since you can define a sync scope, you could restrict it to just the table that you're interested in.
Here are some links where you can read more about this:
MSDN - How to Choose a Data Synchronization Technology
MSDN - Microsoft Sync Framework
Wikipedia - Microsoft Sync Framework
I have the pleasure of using SyncFx v.2.1 on an application. The client side presently uses SQLCE and the Server side uses Server 2008 r2. I am using a SyncFx proxy and host the server SyncAdapterBuilder code in the WCF service. The client has the SyncAgent and SyncTables and it works fine. I am using the integrated SQL Change Tracking in lieu of the coupled (aka custom / scoped) change tracking because I am not permitted to modify existing schema.
So my issue is that the requirements for the system have changed and I am required to use SQL Express on the client in order to support stored procedures.
Why not merge replication? The requirements also prohibit modification of the schema or the use of triggers. In fact the original version of the app used merge replication with SQLCE before moving to SyncFx for SQLCE.
So how is this done? I've read a lot of conflicting information and I can only assume that this is in response to the ever evolving versions of SyncFx. There are no direct example of how SQL to SQL Express with Change Tracking on both is accomplished. Plus I am trying to transition from a functional SQLCE implementation to Express with as few changes as possible. The client is already capable of using either type of DB, it is just the current sync process that needs to change.
Here is what I've found, but have not had success. I've read every StackOverflow response on the matter and am still not finding a way to do this that actually works.
Database Sync:SQL Server and SQL Express N-Tier with WCF : This MS example works fine with the SyncOrchistrator but provisions side tracking tables and triggers. I was not able to modify this in such a way that change tracking could be used on the client and server.
Sync framework with SQL Server 2008 Change Tracking : StephaneT suggests here that simply by using the normal SQLCE approach with the SQL Express sample sync provider and SyncFx 2.0 techniques only client side table modification would be required. Unfortunately all links to this sample SQL Express provider seem to be removed and other posts from JuneT and even Liam Cavanagh on MSDN suggest moving forward with the new official SqlServerProvider instead of a customized version of the DbServerProvider. Problem is there are no sample implementations of this anywhere and I haven't been able to figure it out through trial and error.
Syncing SQL Server 2008 Databases over HTTP using WCF & Sync Framework : Raj gives the best example (simple and easily translated to SQLCE processes) unfortunately it also uses the SqlExpressClientSyncProvider that seems to have evaporated from the internet. It also requires an anchor table to track the clients, I think I can get away with that as I am not allowed to modify schema on "existing" tables.
So any examples out there that can help me. Essentially I want to port the existing functioning SQLCE SyncFx via proxy with integrated SQL Change Tracking using a SyncAgent to a version that works for SQL Express without changing existing scheama or using triggers. I should also mention that I use filter parameters heavily as there are 150+ tables in the replication and they would be extremely large without filters. I had read some references that said the SqlExpressClientSyncProvider didn't support filters, but this is impossible for me to verify since I can't find a reference to that code that is still good.
Maybe there is a refresh of Raj's example that uses SqlServerSyncProvider
Thanks in advance to anyone that can point me in the right direction!
check out this link and you might still find some of the download links in the comments area working: http://www.8bit.rs/blog/2009/05/debugging-sql-express-client-sync-provider/
take note that even the sample SqlExpressClientSyncProvider uses triggers to track the deletes in the tombstone tables. likewise, you need to have columns in your table to track when a row has been inserted or updated (datetime or timestamp columns).
with regards to filtering, you can easily modify the queries in the adapter to include a filter clause.
the newer SqlSyncProvider does not support Sql Change Tracking as it implements its own tracking mechanism. the newer providers works in a peer-to-peer scenario so its tracking as well from which replica a particular change has come from.
as SQL server support .net well because both come from MSFT. but mostly i use MySQL whenever i need to use a database in application.
for DAL i write Queries in SQL put them in function written in c# and for execution i use connector [for C#.net Mysql.data dll]
i hear that SQL server many way to make data transaction between database and code. i am using the same way from a long time so i want to know are their any other method exist in Mysql who are best to working with Mysql.
My means doing something better not only write queries and put them in function. Well how much way i can use Mysql for doing data-transaction.
i want to know how i can improve Everything who relate to My Mysql data and way to handle queries in code behind c#.
i need a guide who can give me a detailed about Everything about Mysql and give the guideline and news like ASP.NET have for ASP.net
Are their any website for Mysql who continuesly update.
Use stored procedures, and views when possible.