Enlisting a Cosmos transaction in a Sql Server Database Transaction - azure

We are using Entity Framework Core 3 and Cosmos 3.4 with Sql API.
Is it possible to enlist a Cosmos (Microsoft DocumentDb) transaction in a Sql Server Transaction so that the RollBack/Commit applies to Both Sql Server and the Cosmos.
Many thanks

Cosmos DB has no transactional support outside of Cosmos DB itself. Its transactions are either at the document level (e.g. inserting a document) or at a stored procedure level (e.g. modifying several documents within the stored procedure, which takes place within a single partition of a single collection).
There's no way to have actual transactional commit/rollback connected with SQL Server (or any other database) outside of Cosmos DB. You'd need come up with your own strategy for keeping data in sync between the two databases.

Related

Is there any way to querying two tables from two different database without using external table in Azure SQL?

I have to querying two tables from two different databases in Azure SQL. Is there any option available in azure?
If your database are Azure single databases, maybe you can use OPENROWSET (Transact-SQL). It now support Azure SQL database.
Includes all connection information that is required to access remote data from an OLE DB data source. This method is an alternative to accessing tables in a linked server and is a one-time, ad hoc method of connecting and accessing remote data by using OLE DB. For more frequent references to OLE DB data sources, use linked servers instead. For more information, see Linked Servers (Database Engine). The OPENROWSET function can be referenced in the FROM clause of a query as if it were a table name. The OPENROWSET function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query might return multiple result sets, OPENROWSET returns only the first one.
Hope this helps.

Partitionkey is ignored in CosmosDB

I have a flow where I send a json document to the ServiceBus and a function listens to the topic and creates a document in my CosmosDB.
The CosmosDB has the partitionkey "targetid"
When I provide the document from the Function
The document is inserted and I can pull it again from c# using CreateDocumentQuery but I cant see the document in the portal and no logical partitions has been created based on the value in the targetid property.
If I create a document directly from the portal and pulls it with CreateDocumentQuery in my application then the document also has a completely different format than the documents that has been created from the application itself through ServiceBus and Functions.
Cosmos DB Change Feed (what the Cosmos DB Trigger reads) is not available on Mongo DB API accounts at this point. Change Feed is a feature of Cosmos DB and thus, surfaced on the Core / SQL API and, at this point, not available for Mongo DB API accounts.
You can verify the compatibility matrix on the official documentation.
As a side note, the fact that you are also using CreateDocumentQuery means that you are using the Core/SQL SDK. It would make sense for you to use a Core/SQL API account instead if you are not going to use the Mongo DB drivers or clients.

SQL Server to Azure Cosmos DB Migration

Please let me know whether we can migrate stored procedure from Microsoft SQL server to Microsoft Azure Cosmos DB ?
Either with DocumentDB migration tool or any other tool
There's really no direct correlation between the two: Stored procedures within the two databases are completely different. No possible way to migrate them, aside from you doing a complete rewrite. SQL Server stored procedures are written in SQL, vs Cosmos DB's JS-based stored procedures. Plus there is the notion of partitions, context, etc.
And Cosmos DB doesn't offer SQL Server compatibility and isn't a relational database. The Core (SQL) API takes advantage of SQL query language, but only for queries.

Is it possible to use Cosmos DB instead of Azure SQL DATABASE?

I am very excited to use Cosmos DB into my current application instead of Azure SQL database.
Before use Cosmos DB as backend in my current application, I have few questions in my mind those are
In my current application I used Entity framework.
And also used column encryption, dynamic data masking features.
So, if I moved to Cosmos DB instead of using Azure SQL database then how can I achieve those features by using Cosmos DB?
Documentation doesn't specify details about encryption, masking and entity framework.
Can you please tell me “is it possible to use Cosmos DB with above requirements instead of Azure SQL Database?
Entity Framework is specific to relational databases, so it doesn't fit with Cosmos DB's document store (or graph, or tables).
Regarding encryption: Cosmos DB provides encryption-at-rest, built-in. There is no per-property data-masking feature built-in; you'd have to do your own data masking.
Whether you migrate to a document (or graph, or table) store is really up to you, and whether you want to re-shape your data to fit in such a storage model, vs a relational model. No real way to answer that for you. (TL;DR you cannot just switch from relational to, say, document, without any changes, as they are fundamentally different storage concepts).

Can't query between databases in SQL Azure

I have a SQL Azure Database Server and I need to query between the Databases but can't figure out how to accomplish this.
Here is the structure of my databases:
Server.X
Database.A
Database.B
Database.C
In Database.A I have a Stored Procedure that needs to retrieve data from Database.B. Normally, I would reference the database like SELECT * FROM [Database.B].[dbo].[MyTable] but this does not appear to be allowed in SQL Azure.
Msg 40515, Level 15, State 1, Line 16
Reference to database and/or server name in 'Database.B.dbo.MyTable' is not supported in this version of SQL Server.
Is there a way to do this on the database end?
In the final version Databases A & C will both need data from Database B.
Update:
As per Illuminati's comment and answer, the situation has changed since this answer was originally accepted and there is now support for cross database queries as per https://azure.microsoft.com/en-us/blog/querying-remote-databases-in-azure-sql-db/
Original Answer (2013):
Cross database queries aren't supported in SQL Azure. Which means you need to either combine the databases to prevent the need in the first place, or query both databases independently and basically join the data in your application.
Cross database queries are now supported in SQL Azure
https://azure.microsoft.com/en-us/blog/querying-remote-databases-in-azure-sql-db/
Azure SQL DB is previewing Elastic Database Query feature at this point in time that will help you query among Azure SQL DBs with some limitations. You can get detailed information about the feature here.

Resources