Add / Delete on Sync MSSQL Data Connector


#1

@ianward
I have configured Sql Data Adapter by following the steps as mentioned in the following link:

https://docs.realm.io/platform/using-synced-realms/server-side-usage/data-integration/mssql-data-connector

both side data s are successfully synced.

but problem is when i delete/add data from sql server it couldn’t delete from realm server…

can you please advice how can i do that


#2

@javeed6373 How are you running the adapter? What are the logs?

Please email me with your set-up, code, and logs as this issue probably has to do with your environment and set-up


#3

@ianward I m following steps as per the below link

https://docs.realm.io/platform/using-synced-realms/server-side-usage/data-integration/mssql-data-connector

crating my table structure in realmmodel.js and then run loader.js through node.js cmd…

loader.js and adapter.js code same as in the above link.

thanks


#4

@javeed6373 OK well something must have been missed. Please send me your loader.js, adapter.js realmmodels.js, and the output of the logs so I can take a look. You can send it by opening a ticket here if you’d like: support.realm.io


#5

@ianward

please take a look of my code…

adapter.js

const fs = require(‘fs’);
const path = require(‘path’);
const process = require(‘process’);
const SQLServerAdapter = require(‘realm-mssql-adapters’).SQLServerAdapter;
const Config = require(’./config’);
const Models = require(’./realmmodels’);

// Print out uncaught exceptions
process.on(‘uncaughtException’, (err) => console.log(err));

// Unlock Professional Edition APIs
Realm.Sync.setFeatureToken(Config.feature_token);
const admin_user = Realm.Sync.User.adminUser(process.env.ROS_ADMIN_TOKEN || Config.admin_user_token, Config.auth_server_url);

const conf = {
// Realm configuration parameters for connecting to ROS
realmConfig: {
server: Config.realm_object_server_url, // or specify your realm-object-server location
user: admin_user,
},
dbName: Config.database_name,
dbSchema: Config.database_schema,
// SQL Server configuration and database name
sqlserverConfig: Config.sqlserver_config,

// Set to true to create the SQL Server DB if not already created
createSQLServerDB: false,
initializeRealmFromSQLServer: true,

// Set to true to indicate SQL Server tables should be created and
// properties added to these tables based on schema additions
// made in Realm. If set to false any desired changes to the
// SQL Server schema will need to be made external to the adapter.
applyRealmSchemaChangesToSQLServer: false,

// Only match a single Realm called 'testRealm'
//realmRegex: `/*`+Config.database_name,
realmRegex: Config.target_realm_path,

// Specify the Realm name all SQL Server changes should be applied to
mapSQLServerChangeToRealmPath: Config.target_realm_path,

// Specify the Realm objects we want to replicate in SQL Server.
// Any types or properties not specified here will not be replicated
schema: Models,

printCommandsToConsole: false

//compoundPrimaryKeys: {
//    'CustomerAddress': [
//        { property: 'customerid', dbColumn: 'CustomerID', type: 'int' },
//        { property: 'addressid', dbColumn: 'AddressID', type: 'int' },
//    ]
//}

}

var adapter = new SQLServerAdapter(conf);

loader.js

const Realm = require(‘realm’);
const fs = require(‘fs’);
const path = require(‘path’);
const SQLServerRealmLoader = require(‘realm-mssql-adapters’).SQLServerRealmLoader;
const Config = require(’./config’);

const Models = require(’./realmmodels’);

if (process.env.NODE_ENV !== ‘production’) {
require(‘source-map-support’).install();
}

// Print out uncaught exceptions
process.on(‘uncaughtException’, (err) => console.log(err));

// Unlock Professional Edition APIs
Realm.Sync.setFeatureToken(Config.feature_token);
let admin_user = Realm.Sync.User.adminUser(process.env.ROS_ADMIN_TOKEN || Config.admin_user_token, Config.auth_server_url);

const conf = {
// Realm configuration parameters for connecting to ROS
realmConfig: {
server: Config.realm_object_server_url, // or specify your realm-object-server location
user: admin_user,
},
dbName: Config.database_name,
dbSchema: Config.database_schema,
// SQL Server configuration and database name
sqlserverConfig: Config.sqlserver_config,
resetPostgresReplicationSlot: true,

// Set to true to create the SQL Server DB if not already created
createSQLServerDB: false,
initializeRealmFromSQLServer: false,

// Set to true to indicate SQL Server tables should be created and
// properties added to these tables based on schema additions
// made in Realm. If set to false any desired changes to the
// SQL Server schema will need to be made external to the adapter.
applyRealmSchemaChangesToSQLServer: false,

// Only match a single Realm called 'testRealm'
//realmRegex: `/*`+Config.database_name,
realmRegex: Config.target_realm_path,

// Specify the Realm name all SQL Server changes should be applied to
mapSQLServerChangeToRealmPath: Config.target_realm_path,

// Specify the Realm objects we want to replicate in SQL Server.
// Any types or properties not specified here will not be replicated
schema: Models,

printCommandsToConsole: true  

}

var loader = new SQLServerRealmLoader(conf);
loader.init().catch(console.error)

realmmodel.js

const CalendarEvent = {
name: ‘CalendarEvent’,
primaryKey: ‘Id’,
properties: {
Id: ‘int’,
Title: {type: ‘string’, optional: true},
Notes: {type: ‘string’, optional: true},
EventType: {type: ‘string’, optional: true},
DateStart: {type: ‘date’, optional: true},
DateEnd: {type: ‘date’, optional: true},
Alarm: {type: ‘string’, optional: true}
UserId: {type: ‘int’, optional: true},
IsDeleted: {type: ‘bool’, optional: true},
IsCompleted: {type: ‘bool’, optional: true},
VehicleStockId: {type: ‘VehicleStock’},
CompletedOn: {type: ‘date’, optional: true},
OldCustomerId: {type: ‘int’, optional: true},
EndNotes: {type: ‘string’, optional: true}
}
}
module.exports = [
CalendarEvent
];

thanks


#6

@javeed6373 Can you please set printCommandsToConsole: true in the adapter.js and share the logs


#7

@ianward


#8

@javeed6373 Those logs look correct so I will need to see the full logs - particularly when you are adding an object or row. You also want to set debug mode logging with Realm.Sync.setLogLevel(‘debug’);

Please open a ticket at support.realm.io and we can get you sorted