Is it possible to execute query to mirror database? (MS SQL Server 2012) - sql-server-2012

Is it possible to execute query to mirror database? Without stopping mirroring.

In database mirroring you can query the mirrored database only if you create snapshots of that database. In SQL Server 2012, database snapshot is an Enterprise feature.
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2012/cc645993(v%3dsql.110)
If you run queries on the snapshot you'll lave to license it, and are a few things to consider, check link below.
https://learn.microsoft.com/en-us/sql/database-engine/database-mirroring/database-mirroring-and-database-snapshots-sql-server?view=sql-server-ver15
If you're willing to license Enterprise, you'd be better of implementing AlywasOn Availability Groups where you can have a readable secondary.

Related

Migrate on-prem SQL Server database to Azure SQL database

We're in the process of a server migration from an on-prem server (Win2008R2) to Azure PaaS.
To move the DBs, we used the Microsoft Data Migration Assistant (DMA) tool, which worked great and we can connect to the migrated Azure DB via SQL Server Management Studio.
Considering:
Made quite a few changes to the migrated Azure DB (tables, stored procedures, indexes) to work with the apps in Azure
Combined multiple on-prem DBs into one DB in Azure via DMA to save costs
On-prem DB is continually being modified by insert/update operations (multiple tables) during the migration process
Question: what is the best and fastest way to migrate data (all vs missing/updated) considering the above?
I would recommend you to migrate first only the schema of your on-premises databases to Azure SQL Databases and then let Azure SQL Data Sync to migrate the data to Azure and keep it updated on Azure SQL Database.
My suggestion to start with an empty schema on the Azure SQL Database side is because when SQL data Sync finds data on-premises and on Azure it start comparing both databases and that consumes a lot of resources.
On the initial sync SQL Data Sync may consume a lot of resources on the on-premises database server even when having an empty schema on the Azure side, for that you can use SQL Server Resource Governor to cap the CPU used by the data sync sessions in your on premises SQL Server, and this way avoid big performance impact possibly affecting database users.
When you are ready, you can switch your users (gradually or not if SQL Data Sync is on bi-directional mode) to Azure. Once your users have been migrated, you can then remove the member database (the on-premises database) from the SQL Data Sync configuration and stop SQL Data Sync operation.
I disagree with all the answers here.
If you are running on Win2008R2 there is a high chance that you are on an old SQL Server (2008? 2012?) which are both deprecated and unsuitable for Azure SQL Database. And probably the application is also old and not suitable for the Cloud in general. I suggest you a good testing phase.
Here my to do list:
Upgrade SQL Server to SQL Server 2016 on-prem and test if all your queries are still running correctly
Test how ready is your SQL Server to go to Azure SQL Database through Microsoft Data Migration Assistant (DMA) tool or the new Azure SQL Migration extension for Azure Data Studio (came out his month).
Don even think for a second that merging databases will reduce your overall costs. Decide if going multi-tenant or single-tanant not because of the price of the database.
Plan for hours of downtime based on the size of the migration. Don't migrate while your database is modified. Expect downtime. The best way is to take a backup of the day before and then resume the logs.
and test like crazy. This is not gonna be easy because the app is old.
Good luck.
Visual Studio also has a great tool for comparing both schema and data between two databases on different servers.
It can then update the target database with any changes after which you can switch over to use the Azure DB.
This method would require downtime of around 5-30 minutes depending on amount of data, but that might be acceptible depending on your requirements.

How to transfer local database table's data to remote database tables using vb.net with SQL Server

I have a local SQL Server database with many tables. I need to transfer data to a remote SQL Server database using vb.net, and task should be run every 2 hr from application. How is it possible to do this? Please suggest the best way for this.
I think the better way is replication. i don't know the possibilities in SQL Server but it works great in mysql. if you enables the replication in two database(Master- Slave) what ever be the changes you have made in the master will simultaneously in the slave. there is possibilities for Bi-Directional Replication in MySQL.
SQL Server provides various types of replication to extend the possibilities. this article helps you to establish replication in Sql Server

Database tool for inter-db joins

Can someone suggest a database tool? I'm doing an enterprise integration, specifically selecting from both SQL Server and MySQL dbs. I'd like to join tables in SQL Server with tables in MySQL for comparison and testing. Portable if possible, I don't have Admin on the machines I'm running this on. Thanks,
Not sure about the MySQL side of things but you can do this with SSIS (SQL 2005+) or DTS (earlier than SQL 2005) as long as you have drivers that will connect to both instances. You can write a package that will bring in datasets from both servers and store the results wherever (db, flat files, etc).
You could also write a powershell script to query the instances (assuming you have drivers/clients for both SQL Server and MySQL installed on your machine).

SQL Script for SQL Azure

I'm developing an app that uses SQL Azure. I don't have an account to access Windows Azure and I want to start writing SQL script.
Can I use my SQL Server 2008 to test my SQL Azure script?
I would also recommend a SQL Azure account. However, if you dont have access to one, you can create the DB in SQL 2008, then export a SQL Azure compatable script. Then use that script for testing purposes.
Here is a link: http://blogs.msdn.com/b/cesardelatorre/archive/2010/06/04/importing-exporting-data-to-sql-azure-databases-using-bcp-and-sql-scripts.aspx
One thing you should accomodate for when coding for SQL Azure is a failover or retry policy per this article: http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx#comments
Not really, because certain SQL statements are not supported, or partially supported. So unless you are already very familiar with the differences between SQL Azure and SQL Server the general recommendation is to create your scripts against a SQL Azure database.
Opening an Account is really simple. Remember that when you create a SQL Azure database your charges are pro-rated daily. So if you create a development database of 1GB is size (the minimum) you will pay $9.99 per month (plus a really low transfer cost), or "roughly" 33 cents per day. If you create a 1GB database on a Monday and drop it the following Wednesday, you will pay roughly a buck. There are no charges for the master database.
I would agree with Herve. It would likely be best if you actually use SQL Azure as there are some differences between SQL Sever and SQL Azure. You can get a free 30 day account (with no credit card) using the following:
Use this link: http://www.windowsazurepass.com/?campid=9FE3DB53-E4F0-DF11-B2EA-001F29C6FB82
Use this passcode: promo code = DPEWE01
What you want to do is actually the right way, you can create a database in you local SQL Server 2008 instance, I would recommend using latest community edition for this purpose.
Create database, tables.. work on it, then generate a script to later export to SQL Azure.
Make sure to see documentation for pressing changes or things not to use while doing your job that might not be working on SQL Azure.

Sync two SQL Server databases

I have two databases: the source is a database from SQL Server Express by client and the target is a database from SQL Server 2005 database as backup initially. What I need is to sync the source to the target db if there is any difference between them and the sync is one-way from source to target.
I am not sure what tools are available. I tried to google this issue and found MS VS Team Edition (2005) has a tool to sync database, which can generate T-SQL scripts as well. Not sure if this one is good or not. Can I use the script as a scheduled job on SQL Server (target server)? By the way, I don't have Team Edition right now but I do have VS 2005 Prof. Any suggestions?
IMHO by far the easiest and fastest way to sync the two databases one-way (A to B) is to backup database on A and restore it on B. This could be done via T-SQL, let me know if you would like me to post SQL statements
Ideally you would set up Transactional Replication from your source to your target(s). However, since your source is Express edition and Replication does not work with Express as a publisher (source) but only as a subscriber (target), you cannot use it.
The best solution would be to upgrade your Express edition to SKU that supports Replication publishing (ie. Standard Edition).
Log shipping, or manual backup/restore, will not work because it will create an absolutely identical copy of the source db at the target, overwritting any changes made by the target (you mention 'some differences' may exist). Same goes for File/Copy.
SQL Compare tools are OK for a one time manual operation, but they fail at automated operations because they always compare the two databases from scratch, ei. are not capable of synching just what changed. As soon as data grows to a sufficient size, the comparison approach is doomed as it has to ship over the entire database for purpose of comparison alone.
Other solutions are to set up pro-active real-time ETL, but the time/cost investment into this is prohibitive compared with the cost of a SE license and deploying Replication.
Pay to play:
http://www.red-gate.com/products/SQL_Compare/index.htm
Free, open source:
http://www.codeplex.com/OpenDBiff
You should into the SQL Server tools produced by Red-Gate. I've found them to be the best around.
If you have SQL Server 05, you can use replication services(this comes with SQL Server). If you open up your management studio, under your server folders you should see one titled "Replication". From here you can setup subscriptions or publications with push or pull syncs.
Here's MSDN's take: http://msdn.microsoft.com/en-us/library/ms151198.aspx
If this is a one time / once-in-a-while thing, you can use SnapShot Replication.
If you need the databases to be in sync all the time, you can use Transactional Replication.
http://msdn.microsoft.com/en-us/library/ms151847.aspx
In addition to Red Gate tools you can try DB Ghost as well http://www.innovartis.co.uk/. It's most useful as a automated build tool, but does also have an user interface to diff and sync databases. It costs ~$350.00
USing microsoft sync framerok
http://msdn.microsoft.com/en-us/library/ee819079.aspx
http://msdn.microsoft.com/en-us/library/ff928525.aspx