How to Call Webservice/CLR functions from Azure SQL - sql-server

Im using SQL Server 2016. My DB contains Web service calls and .net Assemblies incorporated (CLR Functions).
I'm planning to move my DB to Azure SQL. Is it possible to call Webservices/CLR functions from Azure SQL? I see this article says its not possible. Is there any update/other way around?
How does Cosmos DB support support w.r.to this scenario? Please Suggest

SQL Azure does not support CLR in-database. However, SQL Azure Managed Instance does. So, please look into that option.
Your other possible approach is to consider what logic exists in CLR and see if you can move to T-SQL equivalents. Since CLR was added, we now have batch mode processing (Columnstore) as well as in-memory tables/natively compiled stored procedures. Both options are pretty fast alternatives that may solve your problem. In-memory tables are supported on SQL Azure with >= 1 core due to associated memory requirements. Columnstore works on S3 and above in Standard and on Premium/V-core options.

You cannot use CLR functions on Azure SQL Database but you can use CLR functions on an Azure Managed Instance with some restrictions. Managed Instance cannot access file shares and Windows folders, so the following constraints apply:
Only CREATE ASSEMBLY FROM BINARY is supported.
CREATE ASSEMBLY FROM FILE is not supported.
ALTER ASSEMBLY cannot reference files.
To learn about Azure Managed Instances, please visit this documentation.

Related

Is there no way to use CLR Assembly in Azure SQL?

I'm using since SQL Server 2012 that support CLR Assembly trigger (coded with C#).
But I'm now finding possibility to move Azure SQL but it says CLR Assembly is not supported.
Is it sure that Azure SQL doesn't support CLR Assembly and no way to do it?
Msg 10341, Level 16, State 100, Line 5
Assembly 'MyProject.SQLCLR' cannot be loaded because Azure SQL Database does not support user-defined assemblies. Contact Azure Technical Support if you have questions.
I also found this article but unclear for me.
Does or does not SQL Azure support CLR assemblies?
The fine manual indicates that an sql like:
CREATE ASSEMBLY SomeName
FROM 0x...
WITH PERMISSION_SET = SAFE;
will work; all you have to do is turn your dll into a string of hexadecimal number pairs representing the bytes and put them in where the ... are. The example is at the very bottom of the MSDN doc. It would be important to note though that that doc explicitly states its advice is applicable to Azure SQL Managed Instance which is a relatively recent provision; ensure that is what you have deployed. See this blog for a more in depth discussion

Deploying a CLR Assembly to a different database than the rest of the objects

I am using Visual Studio and a SQL Server Database Project to maintain my database objects through TFS. I have implemented a CLR Assembly for using RegEx Pattern matching in my UnitTests. I want to deploy this CLR to a different database than where the rest of the objects in the database would be deployed to.
Database_1 - contains all of the database objects
Database_2 - contains the CLR Assembly and UDFs for RegEx Pattern Matching.
I would like to create the script to deploy a CLR Assembly and related UDFs to one database, while creating the script which will deploy the rest of the changes to another database. I would like to do this using PRE/POST scripts using sqlcmd as I think this is the easiest way to do this.
Is this possible?
Publishing to another Database requires a different Database Project. They should be able to be in the same solution, but having two different Database projects will allow for different publishing properties (e.g. Target Database, etc).
OR, a very quick and easy to not worry about any of that would be to use the SQL# SQLCLR library of functions (which I wrote). The free version of SQL# contains several RegEx functions as well as many others. You can just save the installation script (once the correct Database name has been edited into the USE statement) into TFS and be done with it :-).

Does Azure SQL Database support two-phase commit (2PC)?

Because I have several unrelated resources to coordinate during commit, I would like to use two-phase commit (2PC) on Azure SQL Database, from Java code (JDBC).
On standard SQL Server, you can do a complex install of some DLL plus some scripts to make available some extended stored procedures, with names like xp_sqljdbc_xa_init or xp_sqljdbc_xa_prepare, that in turn the Microsoft JDBC driver uses to provide the XA semantics of start/end/prepare/commit. But these extended stored procedures aren't available on Azure from what I can see.
Also, by itself, SQL Server doesn't seem to have any PREPARE TRANSACTION primitive, and I don't find one in Azure either.
So how can one do 2PC on Azure?
It's not supported and in many ways incompatible with the benefits and uses cases for cloud computing. There's an excellent blog post by Clemens Vasters that I'd recommend reading and which introduces the service bus feature as a way to accommodate the key aspects of the behavior that you may be looking for.

Entity Framework, No SQL server, What do I do?

Is there seriously no way of using a shared access non-server driven database file format without having to use an SQL Server? The Entity Framework is great, and it's not until I've completely finished designing my database model, getting SQL Server Compact Edition 4.0 to work with Visual Studio that I find out that it basically cannot be run off a network drive and be used by multiple users. I appreciate I should have done some research!
The only other way as far as I can tell is to have to set up an SQL server, something which I doubt I would be able to do. I'm searching for possible ways to use it with Access databases (which can be shared on a network drive) but this seems either difficult or impossible.
Would I have to go back to typed DataSets or even manually coding the SQL code?
Another alternative is to try using SQL
Install SQL Server express. Access is not supported by EF at all and my experience with file based databases (Access, SQL Server CE) is mostly:
If you need some very small mostly readonly data to persist in database you can use them (good for code tables but in the same time such data can be simply stored in XML).
If you expect some concurrent traffic and often writing into DB + larger data sets their performance and usability drops quickly. They are mostly useful for local storage for single user.
I'm not sure how this relates for example to SQLite. To generate database from model for SQLite you need special T4 template (using correct SQL syntax).
Have you tried SQLite? It has a SQL provider, and as far as I know EF supports any provider. Since it's file-based, that might be a plausible solution. It's also free.

Alternatives to SMO, i.e. DML APIs for SQL Server?

I just learned I can't use SMO in ASP.NET without either SQL or a full SMO install on the application server. I'm not allowed to do that, so I can't use SMO.
What other libraries do the same thing as SMO but don't require an MSI installer or COM registrations?
I know I could send DDL to the server inside ADO.NET commands, but that is exactly what I was trying to avoid by using SMO.
What was nice about SMO:
Object oriented API for querying meta-data (columns, data types) that didn't rely on inconsistent COBOL-like DDL.
Didn't require querying undocumented stored procedures, system stored procedures or tables which break every few versions.
Off the top of my head I can think of ADOX and DMO, but both were COM based APIs.
SMO is running T-SQL under the covers. You could prototype in SMO and then watch in profiler to get the T-SQL.
It is probably an EULA violation, but you could redistrib the SMO assemblies side-by-side with your app, nothing to install in that case. I don't think their installer hits the registry. Pretty easy to bust open the SQLServerManagementObjects.msi and find out.

Resources