Microsoft sync framework 2.1 ServerSyncProviderProxy with client SQL Server Express - sql

I've been following the tutorial here to configure a proxy service with WCF for synchronization. But all the examples I see the ClientProvider is for SqlServer Compact Edition. Can it be done with the SqlSyncProvider for SQL Server Express?
For example my code is:
var svc = new ServiceForSyncClient();
ServerSyncProvider serverProvider = new ServerSyncProviderProxy(svc);
// create the sync orhcestrator
var syncOrchestrator = new SyncOrchestrator
{
LocalProvider = new SqlSyncProvider("ProductsScope", clientConn),
RemoteProvider = serverProvider,
Direction = SyncDirectionOrder.DownloadAndUpload
};
var syncStats = syncOrchestrator.Synchronize();
But when synchronizing, I get an exception:
An unhandled exception of type 'System.InvalidCastException' occurred
in Microsoft.Synchronization.dll
Additional information:
Microsoft.Synchronization.KnowledgeSyncProvider

you're using two completely different sync providers. part of your code is using the the older offline providers (DBServerSyncProvider and SQLCEClientSyncProvider) and you're trying to use the SQLSyncProvider which is part of the newer knowledge-based/peer-to-peer sync provider (SqlSycProvider/SqlCeSyncProvider).
You can't mix and match the older and newer sync providers
If you want to use SQL Express as the client, here is a sample for using it with WCF

Related

How to make database connectivity in ASP.NET core with PostgreSQL?

How to make database connection in ASP.NET core with postgres SQL ?
Question: How to make database connection in ASP.NET core with postgres SQL ?
There are two ways you add your postgresql database along with the asp.net core project.
Using follwing way:
ADO.net connection provider
Nuget extension: Npgsql.EntityFrameworkCore.PostgreSQL
ADO.net connection provider
Here would just need the NpgsqlConnection connection builder class which will execute your sql on Postgre sql database server. See the example below:
C# ASP.NET Core & Postgre SQL Ado.net example:
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=postgres;Password=pwd;Database=postgres;");
conn.Open();
// Passing PostGre SQL Function Name
NpgsqlCommand command = new NpgsqlCommand("EXE GetEmployeePrintInfo", conn);
// Execute the query and obtain a result set
NpgsqlDataReader reader = command.ExecuteReader();
// Reading from the database rows
List<string> listOfManager = new List<string>();
while (reader.Read())
{
string WSManager = reader["WSManager"].ToString(); // Remember Type Casting is required here it has to be according to database column data type
listOfManager.Add(WSManager);
}
reader.Close();
command.Dispose();
conn.Close();
Npgsql.EntityFrameworkCore.PostgreSQL:
You have to add Nuget extension into the project reference from manage Nuget Packages using Visual studio. Entity framework core has this functionality for many database providers. Just follow below steps on visual studio
ConfigureServices in startup.cs:
Once you successfully added the Nuget package then you have to update following code on your project ConfigureServices under startup.cs
services.AddDbContext<YourDatabaseContextClassName>(options =>
options.UseNpgsql(Configuration.GetConnectionString("YourDatabaseContextStringNameFromAppsettings")));
Note: If you need any example for entityframework and Postgre SQL implementation you can have look here
For further assistance you can have look on official document here. Hope it would guide you accordingly.

Does smbj API support SMB v3.x dialect versions?

Exception is thrown while opening SMB connection using smbj API. It says: "SMB 3.x support is not yet implemented". The exception is thrown from "SMB2NegotiateRequest.putCapabilities(SMBBuffer buffer)" method.
Below is the code snippet that opens the connection. The ides is to establish connection with server which supports any of the mentioned dialect version.
SMB2Dialect [] supportedSmdDialects = {
SMB2Dialect.SMB_2_0_2,
SMB2Dialect.SMB_2_1,
SMB2Dialect.SMB_2XX,
SMB2Dialect.SMB_3_0,
SMB2Dialect.SMB_3_0_2,
SMB2Dialect.SMB_3_1_1
};
SmbConfig cfg = SmbConfig.builder().
withDialects(supportedSmdDialects).
withMultiProtocolNegotiate(true).
build();
SMBClient client = new SMBClient(cfg);
Connection conn = client.connect(host); // This line throws
In anything wrong with this code, or smb v3x is not implemented in fact?
Currently indeed SMBv3 support is not implemented. To connect, remove the SMB3+ dialects from the array.

Serilog MSSqlServer sink not writing to table

I have the following statement in my Startup.cs:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.ColoredConsole()
.WriteTo.MSSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=myDb.Logging;Trusted_Connection=True;", "Logs", autoCreateSqlTable: true)
.WriteTo.RollingFile(pathFormat: Path.Combine(logPath, "Log-{Date}.txt"))
.CreateLogger();
And in my Configure method:
loggerFactory.AddSerilog();
When I start the application, the table is created so I know the connection works. I get logged output to the console and to the file, however, no output to the database table.
What am I failing to do?
Other information: using asp.net core rc2-final, targeting net461, and using Serilog.Sinks.MSSqlServer 4.0.0-beta-100
At first glance it doesn't look like you're missing anything. It's likely that an exception is being thrown by the SQL Server Sink when trying to write to the table.
Have you tried checking the output from Serilog's self log?
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine(msg));
Update:
Looks like a permission issue with you SQL Server/Local DB. This error message suggests the sink is trying to run an ALTER TABLE statement and the user running the application doesn't have permission to execute an ALTER TABLE statement.
Update 2: I suggest you write a simple Console App using the full .NET + Serilog v1.5.14 + Serilog.Sinks.MSSqlServer v3.0.98 to see if you get the same behavior... Just to rule out the possibility that there's a problem with the .NET Core implementation or with the beta sink version you're using

Migrating from TableServiceContext to CloudTable

I am migrating my Azure code from using TableServiceContext to CloudTable, due to the following warning (migrating to the latest Azure SDK from an older version)
'Microsoft.WindowsAzure.Storage.Table.DataServices.TableServiceEntity' is obsolete: 'Support for accessing Windows Azure Tables via WCF Data Services is now obsolete. It's recommended that you use the Microsoft.WindowsAzure.Storage.Table namespace for working with tables.'
One of the problems is that in TableServiceContext I used the following
_tableServiceContext.MergeOption = MergeOption.NoTracking;
_tableServiceContext.SaveChangesDefaultOptions = SaveChangesOptions.ReplaceOnUpdate;
_tableServiceContext.IgnoreResourceNotFoundException = true;
_tableServiceContext.Format.UseAtom();
_tableServiceContext.WritingEntity += JobRepository_WritingEntity;
Whats the equivalent in the new SDK?
These properties are specific to the behavior of the ServiceContext, and do not apply to using the CloudTable class.

Automatically Sync SQL Databases across two computers

I am using a cloud backup/sync service (SpiderOak) which automatically Syncs folders across several computers / devices.
I am trying to figure out a way to automatically sync all my databases across my work computer and personal laptop, without actually needing to backup/restore from one instance to the other.
So what I am thinking of is to create a new sql instance on my laptop which is identical to my work desktop instance, then to pick both SQL Server directories in Program Files to sync with each other using SpiderOak (the whole root SQL Server folders).
Will this be enough for my two instances to Sync with each other? Meaning if I create a new database on my computer at work, will I see this database on my laptop when I open SQL Server Database Management Studio?
I am almost sure if databases already exist they will sync with each other (since the root folders contain the mdf & ldf files - but correct me if I am wrong). however, I am not sure if a new database will be created if it doesn't already exist on one of the machines.
Is there any other folders that I need to sync other than the ones I specified already?
You could use Sql Sync Framework, you can download it here
some more readfood
It works for Sql Server 2005
Download and import references and include with the default ones:
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServer;
using System.Diagnostics;
using System.Reflection;
using System.Net;
Than the actual code:
private void SyncTables()
{
SqlConnection ConStringOnline = new SqlConnection("connstring");
SqlConnection ConStringOffline = new SqlConnection("connString");
SyncOrchestrator sync = new SyncOrchestrator();
sync.Direction = SyncDirectionOrder.Download; //or DownloadAndUpload
//the 'scope1' is important, read more about it in the articles
var provider1 = new SqlSyncProvider("scope1", ConStringOnline);
var provider2 = new SqlSyncProvider("scope1", ConStringOffline);
PrepareServerForProvisioning(provider1);
PrepareClientForProvisioning(provider2, ConStringOnline);
sync.LocalProvider = provider2;
sync.RemoteProvider = provider1;
sync.Synchronize();
}
private static void PrepareServerForProvisioning(SqlSyncProvider provider)
{
SqlConnection connection = (SqlConnection)provider.Connection;
SqlSyncScopeProvisioning config = new SqlSyncScopeProvisioning(connection);
if (!config.ScopeExists(provider.ScopeName))
{
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(provider.ScopeName);
scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("TABLENAME", connection));
config.PopulateFromScopeDescription(scopeDesc);
config.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
config.Apply();
}
}
private static void PrepareClientForProvisioning(SqlSyncProvider provider, SqlConnection sourceConnection)
{
SqlSyncScopeProvisioning config = new SqlSyncScopeProvisioning((SqlConnection)provider.Connection);
if (!config.ScopeExists(provider.ScopeName))
{
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(provider.ScopeName, sourceConnection);
config.PopulateFromScopeDescription(scopeDesc);
config.Apply();
}
}
The downside of using Sync Framework: It is a pain in the a** to add these prerequisites to your application before publishing, no problem if you just use an application for yourself or for your company, but when you would like to publish it online it is a bit harder. I already had a topic about that
However, when using tools like InnoScript, you can install the prerequisites easily while installing the application. Here is how.
Now for the ScopeName: It is important that you don't use twice the same name, I believe. I had multiple tables so I just named them scope1,scope2,scope3,scope4. Apparently Sync Framework does the rest of the work for you. It also automatically adds _tracking tables to your database, this is just metadata to store information to synchronize properly.