Saturday 17 March 2018

What are Cache Snapshots And History Snapshots in SSRS 2016 ? - Simple Explaination.


While taking training classes for national and International students, I have often seen them getting confused with the way snapshot options work in SSRS 2016. So I thought of putting it in an article.

The first thing to understand here is what a snapshot is? As the name suggests, just like a picture, A snapshot is a picture of data at that given moment. Once you click a snapshot, it stays that way and doesn’t change unless you replace it with another snapshot.

Same way in SSRS, a snapshot stores the data of a report at a given moment. After understanding what a snapshot is, let’s now explore the snapshot options in SSRS 2016. There are actually 2 options in SSRS related to snapshots:

1.        First option is to always run a report from a snapshot. What this means is that your report will always pull data from a predefined snapshot. Below image shows this option:





Here I have selected the RedBushSalesReport to be run from a snapshot.
You may choose the option “Create a cache snapshot when I click Apply on this page”, if you choose to create the snapshot immediately after you click the Apply button. There afterwards, your report will always pull data from this snapshot. If the data changes in database, you will still keep getting the same data.
Also note that if the report has any parameters, then you need to specify a default value for them to generate the snapshot as shown below:



If you don’t specify default values for parameters, then you will get below error:






Now if you run/refresh multiple times, you will notice that report is returning same data. Notice that you will not be allowed to change the parameter value now! Since the report is supposed to come from a snapshot, which has a default parameter, you will be able to run it with that default parameter(s) only. I refreshed the RedBushSalesReport multiple times, and every time it displayed the same execution time, which confirms that the data is coming from a static snapshot. Also I am not able to change the parameter also.






Sometimes you may have a requirement to run a report with fixed parameters on daily basis and if the report is really heavy and takes time to generate, then you may choose to schedule the snapshot, say before the office times starts and then everybody will be able to run the report quickly. And your boss will be happy to see the performance! Remember you should schedule the snapshot depending upon how long you can afford to show the stale data. Below image shows the scheduling of snapshot:



Notice that whenever you are generating snapshots using any of the above two options, by default no history of snapshots is being maintained. You can check this by clicking the “History Snapshots” option.



Now let’s see what History snapshots are. The main purpose of  a Report History snapshot is to keep a copy of the report at a specific point of time. So if you want to keep track of how your report looked at different points of time. You can generate the History Snapshots by clicking the “New History Snapshot” button as shown below:



If I click the “View History Snapshot” button, I will see the report with this new snapshot. What will happen if run the report normally by going back to “Browse”? Will I see the report with this snapshot or the older snapshot that we generated? We will see the report with older snapshot only. So that means your report doesn’t pull data from history snapshots. They are just used to keep a trail of how your report looks at different specific times.

Can I keep a history of snapshots that I generate from the Caching tab? Yes, you can. From History snapshots tab, go to Schedule and Settings option as shown below:



Using this option, you can specify to save Cache snapshots in History as well. You cal also specify how many history snapshots you want to retain. Additionally you can generate the History snapshots at pre defined schedule. All these options are shown below.




So you must have noticed that there can be only one report execution snapshot at a time, but there can be many History snapshots.


I hope this clarifies the difference between History snapshots and report execution cached snapshots.


If you have any questions, I’ll be happy to respond in the discussion forum of this article.

Contact us at - support@redbushtechnologies.com 


Author is a senior DBA, Mr Suresh, with more than 16 years of experience in the IT industry. He delivers lectures on SQL Server and consult many MNCs. His detailed profile can be viewed at :-   www.sureshdbagurugram.com


Thank you 
Team RedBush

Sunday 7 January 2018

How to Configure Transnational Replication with Multiple Publishers, Single Subscriber



While providing a replication solution to one of my client in SQL Server 2016, I came across a scenario where the client had retail stores at various locations and all data from those stores had to be synchronized at a central location in real time. The aim of this synchronization was to make it easy for senior management to analyze all stores performance from a single location. After giving considerations to different options, I finally came up with a solution that worked for my client.

Let’s assume we have server  RBTSERV1 and RBTSERV2, which will act as publisher for 2 stores. RBTSERV3 will act as a subscriber and data from both servers RBTSERV1 and RBTSERV2 will be synchronized to RBTSERV3.

There were several tables that needed to be synchronized but to keep it simple, I will take 1 table in our example.

Notice that All stores have a unique StoreId assigned to them.Let’s create some sample table and data on all servers.

--RBTSERV1:PUBLISHER 1
create database DBPub1
use DBPub1
create table CustomerOrders(StoreID int ,OrderId int, ItemName varchar(100), Qty int, OrderDate datetime default getdate()
, CONSTRAINT PK_CustomerOrders PRIMARY KEY (StoreID,OrderId))

INSERT INTO CustomerOrders VALUES (1,1,'Books',5,Getdate())
INSERT INTO CustomerOrders VALUES (1,2,'Toys',3,Getdate())
---------------------------------
--RBTSERV2: PUBLISHER2
create database DBPub2
use DBPub2
create table CustomerOrders(StoreID int ,OrderId int, ItemName varchar(100), Qty int, OrderDate datetime default getdate()
, CONSTRAINT PK_CustomerOrders PRIMARY KEY (StoreID,OrderId))

INSERT INTO CustomerOrders VALUES (2,1,'fans',15,Getdate())
INSERT INTO CustomerOrders VALUES (2,2,'pens',13,Getdate())
---------------------------------
--RBTSERV3:SUBSCRIBER
create table CustomerOrders(StoreID int ,OrderId int, ItemName varchar(100), Qty int, OrderDate datetime default getdate()
, CONSTRAINT PK_CustomerOrders PRIMARY KEY (StoreID,OrderId))

So publisher RBTSERV1 has 2 records in the table and publisher RBTSERV2 also has 2 records in the table. Subscriber doesn’t have any records.

Now let’s start with our replication.

Configuring Publication on RBTSERV1:
To setup a publication on RBTSERV1, Follow the below steps:
1.       Right Click on folder “Local Publication” and select “New Publication...”



2.       In the publication wizard, select the database to be used for Publication. In our case, we are using DBPub1.



3.       Since we have to make the sync almost real time, so we choose Transaction replication.





4.       Next we pick the table we wish to use for our replication. Here the important point is to choose the “Properties for all Table Articles” under “Article Properties” as below:
Action if name is in use: Keep Existing Object Unchaged



5.       Next we leave the “Create a Snapshot Immediately...” option unchecked.




6.       Under Agent security, choose the options below. Note that on my server, SQL and Agent services are running under administrator account.




7.       Give your publication a name and click Finish.



8.       The publication wizard should finish without any error.




9.       Next repeat the same steps for RBTSERV2 and give your publication a name SERV2_Publication.
10.   Now right click on Publication SERV1_Publication and choose “New Subscriptions...”.  In the Subscription wizard, choose your publication as SERV1_Publication





11.    Then you select if you wish to have a push or pull subscription. Here I have used Push Subscriptions






12.   Now you select your subscriber name and the subscription database. Here I have used RBTSERV3 as subscriber and DBSubs as subscriber database.



13.   Configure the distributor Agent security.



14.   Choose to run the distributor Agent Continuously.



15.   It is important not to initialize the subscription as we will be manually synchronizing the old data.




16.   Finally finish the subscription wizard.



17.   Now if you check the log reader agent status of RBTSERV1 or RBTSERV2, you should see it running fine. 



18.   And now if you check data in subscriber table using below query, there should be no data. SELECT *   FROM [DBSubs].[dbo].[CustomerOrders]

Now let’s add some new records to both servers.

--RBTSERV1
INSERT INTO CustomerOrders VALUES (1,5,'notebooks',15,Getdate())
--RBTSERV2
INSERT INTO CustomerOrders VALUES (2,6,'erasers',150,Getdate())


19. Now finally check that the new records from both stores have come to subscriber table.



20.   Now you can sync the old records from both stores either using a SQL query or export import wizard. Now in future if you wish to reinitialize just one store, you may delete the data of that store from subscriber and manually sync the data from that store using queries
or export import wizard.


 So that's that. Hope it helped. If you have any issue in understanding the article, feel free to contact us and we will surely help you. Call or whatsapp - +91 997148322

email- support@redbushtechnologies.

Author- Suresh Kumar - A seasoned SQL DBA with more than 15 years of experience in working with fortune 500 MNCs.

Thank you
Team RedBush