Data moved from one database to another database in same SQL server in C/AL ?

Pradeep1611
Member Posts: 8
Hi Folk,
Need your assist.
I need to moved "Change Log Entries" table data from one database to another database in same SQL server in C/AL code, is this possible or not in C/AL code?
Thanks in advance.
Need your assist.
I need to moved "Change Log Entries" table data from one database to another database in same SQL server in C/AL code, is this possible or not in C/AL code?
Thanks in advance.
0
Best Answer
-
To achieve this, you need to do several things:
- Make a new table in your _another_ database that will store your changelog, define columns, keys, etc in SQL
- Create a new table in your NAV database using Development Environment. It must have the same columns (fields) and primary key as the table you made in the another database. Before you save it, make sure you define 3 extra properties on the table - TableType = ExternalSQL; ExternalName = <name of the table in another DB without the schema>; ExternalSchema = <name of the schema of the table, by default [dbo]>
- Next you need to establish a link to the other database. Use command REGISTERTABLECONNECTION to do so. An example of the "connection" parameter: "Data Source=tcp:<databaseAddress>,<port>;Initial Catalog=<databaseName>;User ID=<userID>;Password=<password>"
- Now you can use that table as any other normal table in CAL to read/write/delete to/from it
5
Answers
-
Not totally in CAL only.
In principle you can create a change log table as a view towards a different database. Move your records from the existing change log entries to there, rename the view to companyname$Change Log Entries (deleting the normal change log table) and change Change log Entries to a linked object. Not completely trivial, but certainly doable1 -
Thanks @jln for solution but my requirement is data moved in another database table from one database in C/AL code. example suppose I created one nav database and at the same time I created an another nav database having all table same properties, So now my requirement is data moved from one database to another database in respective table, which code written in C/AL.
again thanks @jln0 -
@Pradeep1611 - You talking about two different things -
1. If you simply need to move the logs of change log to different Database then do it from SQL however you want with the filters and doing with SQL is best option.
2. If you want this to always happen like executing in DB1 and logs getting inserted in DB 2 then it you need to do a lot of customisation and write your codes for every instance, it will be a cumbersome job.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
@RockWithNAV thanks for your helpful suggestion, Yes your 2nd option I needed, 1st option it can also fulfilled my requirement but I need completed my requirement with your 2nd option because I don't want to depended on SQL developer and any type of middle ware work like calling procedure of SQL from Window Task scheduler etc etc.
So I need fulfilled my requirement with the help of C/AL only from a particular Codeunit, once codeunit run then required table data will moved from one database to another database in respective configured table.
Thanks @RockWithNAV .0 -
To achieve this, you need to do several things:
- Make a new table in your _another_ database that will store your changelog, define columns, keys, etc in SQL
- Create a new table in your NAV database using Development Environment. It must have the same columns (fields) and primary key as the table you made in the another database. Before you save it, make sure you define 3 extra properties on the table - TableType = ExternalSQL; ExternalName = <name of the table in another DB without the schema>; ExternalSchema = <name of the schema of the table, by default [dbo]>
- Next you need to establish a link to the other database. Use command REGISTERTABLECONNECTION to do so. An example of the "connection" parameter: "Data Source=tcp:<databaseAddress>,<port>;Initial Catalog=<databaseName>;User ID=<userID>;Password=<password>"
- Now you can use that table as any other normal table in CAL to read/write/delete to/from it
5 -
@ShaiHulud thanks a lot for the solution, Hope this will work I also did same but I missed about company change parameter.
Thanks for the valuable solution @ShaiHulud0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions