SQL # |
Expanding the capabilities of T-SQL |
||||
Home
Features
Benefits
F.A.Q.
Contact Us
Full Version Free Version Documentation |
❗❗ Version 4.0 Announcement ❗❗ | ||||
SQL CLR Library , SQLCLR , CLR Routines , CLR Library , SQL Server CLR , Bulk Export , Regular Expressions , HTML Export , Generate Insert Statements , Median , Automation , RegEx
⸦ F. A. Q. ⸧
So, what exactly is this "SQLCLR"?
CLR stands for Common-Language Runtime.
This is what makes .NET function.
When code is written in any .NET language (e.g. C#, VB.Net, Visual J#, or Visual C++),
it gets compiled down to a common, intermediate language called p-code (originally called Microsoft Intermediate Language [MSIL], then renamed to Common Language [CL], but still referred to as MSIL in some documentation).
The .NET CLR runs this MSIL / CL on the Operating System.
This is why you need to have the .NET run-time on a machine in order to run .NET programs.
It is also why all of those languages mentioned can make [mostly] equal use of the .NET Framework and resources.
Here is a short video from Microsoft with an overview of SQLCLR.
What does the .NET CLR Integration feature (starting in Microsoft SQL Server 2005) do? Does it replace T-SQL?
Microsoft included the .NET CLR inside of SQL Server starting with SQL Server 2005.
This allows for Stored Procedures, User-Defined Functions, and Triggers to be able to make use of the .NET Framework via any of the .NET languages (C#, VB.Net, Visual J#, and Visual C++).
No, this does NOT replace T-SQL.
T-SQL is still the ONLY way to manipulate and retrieve data in SQL Server.
Even if you create a SQLCLR Stored Procedure or User-Defined Function, you will still have to connect to the database inside of it and issue T-SQL commands.
Granted, the connection to the database inside of a SQLCLR Procedure or Function is much more efficient than an outside call from the application since the connection already exists (as you are already in the database) and you just use it.
However, you would not want to use the CLR for anything that does not have complex logic or is not procedural in nature as the most efficient mechanism for data retrieval and manipulation is still standard T-SQL via a Stored Procedure or User-Defined Function.
So, the true benefits of the CLR are: a) the ability to more efficiently / quickly perform procedural logic, and b) the ability to make use of the .NET framework functionality that could never be duplicated in T-SQL anyway.
THIS is where SQL# comes to the rescue.
SQL# brings the useful aspects of .NET via the CLR into the T-SQL world so that now T-SQL can do so much more!
Please see the following article I wrote on SQL Server Central for a more in-depth look at what SQLCLR can do and when it makes sense to use it (free registration is required to access their content): Stairway to SQLCLR Level 1: What is SQLCLR? Does SQL# (SQLsharp) work with Microsoft SQL Server 2000 (or before)?
Unfortunately, no.
SQL Server 2005 is the first version to incorporate the .NET CLR inside the database engine so the previous versions would have no way to make use of .NET code.
If you are stuck using SQL Server 2000 (or before) for a while and need to do complicated, procedural logic, the only way is to create a COM DLL and register it as an Extended Stored Procedure (xp).
See Books Online (BOL) for more detailed information on creating and registering xp DLLs in SQL Server 2000. Please note that Extended Stored Procedures are deprecated as of SQL Server 2005.
What versions of Microsoft SQL Server does SQL# (SQLsharp) work with?
SQL# works with most versions of Microsoft SQL Server released after 2000, specifically:
The only SQL Server offerings that do not support SQLCLR (and by extension, SQL#) are:
What about security? Is SQL# safe?
SQL# is as safe as you want it to be. Regardless of the security level set for the SQL# Assembly, .NET CLR code has the same permissions as any other T-SQL code based on either the user running the code,
or the user specified in the
EXECUTE AS clause of the Stored Procedure or User-Defined Function.
All SQL# Procedures and Functions are created with EXECUTE AS CALLER so that anyone who runs any SQL# Procedures or Functions will only be able to do what the DBA has already allowed them to do.
The CLR canNOT be used to circumvent database security; it works WITHIN the confines of the database's security.
That being said, the SQL# Assembly is loaded with a default setting of SAFE. You will see this when you get the install SQL script as it creates the Assembly.
Updates to the SQL# Assembly done via the SQLsharp_Update Stored Procedure will NOT change the security setting of the SQLsharp Assembly prior to the update.
There are some SQL# User-Defined Functions and Stored Procedures that require EXTERNAL_ACCESS to get to the InterNet.
If you want to use any of these InterNet or FileSystem functions, you will need to change the security setting via the SQLsharp_SetSecurity Stored Procedure.
If you use that Procedure to set the security level of the SQL# Assembly to either EXTERNAL_ACCESS or UNSAFE , it will also set the database property of is_trustworthy_on to TRUE (who are we kidding, it’s "1" in SQL Server ;-).
You can read more about security in relation to the CLR here:
Security in the CLR World Inside SQL Server (https://www.devx.com/codemag/Article/31193)Please see the following two articles I wrote on SQL Server Central for a more in-depth look at SQLCLR security: Stairway to SQLCLR Level 3: Security (General and SAFE Assemblies) Stairway to SQLCLR Level 4: Security (EXTERNAL and UNSAFE Assemblies) What happens when I backup and restore the database? Do I also need to keep a copy of SQL# (SQLsharp) on the filesystem?
In SQL Server 2000, COM DLLs registered as Extended Stored Procedures (xp) always point to the DLL file on the filesystem.
This means that you have to keep a copy of those DLLs around so that code in the database that references those Extended Stored Procedures continue to function.
In contrast, .NET Assemblies in SQL Server 2005 (and beyond) are loaded directly into the database and do not point to any location outside of the database.
This has the benefit of ensuring that through backups and restores, code in the database that points to these .NET Assemblies continues to function.
How do I know what version I have installed?
That's easy. Just run the following query:
SELECT SQL#.SQLsharp_Version();
How do I know when upgrades are available?
There are two ways to check for updates:
How do I get these upgrades?
There are two ways to get the updates:
I have an idea for a new SQL# function. Will you include it?
I will consider most anything. Use the Contact Us form to send any suggestions.
I don't want SQL# installed anymore. How do I get rid of it?
Easily (though you shouldn't because it's so great!). Just run the following Stored Procedure (in the Database where SQL# is installed):
EXEC SQL#.SQLsharp_Uninstall; This will remove ALL Stored Procedures, User-Defined Functions, User-Defined Types, and User-Defined Aggregates linked with the SQL# Assemblies and then remove the SQL# Assemblies. It will also remove the SQL# Schema (if it is empty), and it will remove the SQL# User. Starting in version 4.0, if you have installed the Instance-level objects (this happens in most installations) and want to remove those, just execute the following: EXEC [master].[dbo].[SQLsharp_InstanceUninstall];
How do I check my current security settings?
Easily. Just execute the following Stored Procedure:
EXEC SQL#.SQLsharp_SetSecurity 0; This will show the current setting for both the database and the SQL#_2 Assembly.
I don’t want to set
EXTERNAL_ACCESS but I still would like to be able to update via SQLsharp_Download . Is this possible?Sure. Just execute the following sequence of Stored Procedures:
EXEC SQL#.SQLsharp_SetSecurity 2 -- open up InterNet access (2 = EXTERNAL_ACCESS) GO EXEC SQL#.SQLsharp_Download -- get the update now that we temporarily opened up InterNet access GO EXEC SQL#.SQLsharp_SetSecurity 1 -- close any type of external resource access (1 = SAFE) GO Note: If the database property of is_trustworthy_on was previously FALSE before setting the security to 2 (for EXTERNAL_ACCESS ) AND you are using a version of SQL# prior to 3.0.x,
it will be set to TRUE by the act of setting level 2 but will NOT be set back to FALSE when setting security level 1 (for SAFE) as there is no way to determine who set is_trustworthy_on to TRUE or why or when.
If you need to set is_trustworthy_on back to FALSE, you can do that via the T-SQL command:ALTER DATABASE {DBName} SET TRUSTWORTHY OFF Does SQL# work with Azure SQL Database (Microsoft’s cloud-based SQL Server)?
Sadly no. As of December 2016, Azure SQL Database (formerly named SQL Azure) does not support SQLCLR (see here). Hopefully SQLCLR will be supported by SQL Azure in the near-future.
Please note that while support for SQLCLR (SAFE Assemblies only) was added in late 2014 to Azure SQL Database V12, it was removed (supposedly temporarily) on April 15th, 2016. Does SQL# work with Amazon Relational Database Service (Amazon RDS: Amazon’s cloud-based SQL Server)?
YES! Microsoft SQL Server on Amazon RDS does support SQLCLR for Assemblies marked as SAFE (see Version and Feature Support on Amazon RDS) for SQL Server versions 2012, 2014, and 2016. SQL# version 4.0 has been tested on an Amazon RDS instance of SQL Server 2016 SP1 CU2.
Running SQL# on Amazon RDS requires two things:
Are SQLCLR Stored Procedures and Functions slower than using T-SQL?
This greatly depends on what the exact operation is.
For many simple tasks, straight T-SQL is much faster than SQLCLR.
However, as operations get more complex, the efficiency of SQLCLR typically overtakes the straight T-SQL approach, especially when comparing UDFs / TVFs.
I published a study — CLR Performance Testing — which shows that SQLCLR performs quite well, but as one would expect, sometimes straight T-SQL is clearly the better choice.
It all comes down to testing your particular situation. However, if you are not dealing with a lot of data and/or transactions, then the differences in performance might not be noticable.
Can I distribute (i.e. include) SQL# with my application?
As stipulated in the License Agreement:
The licensee may not distribute the Full (Paid-For) version of SQL# to anyone who does not work for the licensee and/or who will not use it for the business of the licensee. If you are interested in a Distribution License (for an additional cost), please contact us via the contact form located at https://SQLsharp.com/contact/. Is the source code available?
At the moment there is no option to get the source code. There had been plans to offer a Source Code License for an additional cost, but for now those plans have been put on hold indefinitely.
How is the Full version of SQL# licensed? Per Server? Per Instance? Per Database?
The Full version of SQL# is licensed per “Production” server, with a current maximum of 20 servers for the per-server pricing. 21 or more Production servers is a flat fee and is considered a Site License.
For the purposes of licensing, "Server" is defined as an individual, active instance of an Operating System, containing at least one active Instance of Microsoft SQL Server. SQL# can be installed on any number of databases. SQL# can also be installed on any number of non-Production servers (e.g. development, testing, etc.), workstations, and Production-level passive cluster nodes, provided that the appropriate number of Production servers have been licensed. How long is the license period?
Each license period, whether initial purchase or upgrade, is for 2 years (i.e. 24 months).
Does SQL# expire? Does the Full version of SQL# stop working after the license period?
Non-beta versions never expire or stop working (this applies to both Free and Full versions). Time-limited software is greatly complicates administration and management. An expiration date would be an impediment to someone getting their job done, and the goal of Sql Quantum Lift is to provide tools that reduce complications, not add to them.
However, beta versions do have expiration dates. The reason for this is that beta versions are, by definition, not Production-ready code and so should not be installed and forgotten about. Having an expiration date (on beta versions only!) ensures that "incomplete" and/or "unverified" code is not still running 20 years from now, on a server that is sitting in a corner, and nobody who currently works for the company was around when the server was installed, and the admin who put it there left only a note stating "Critical system! Do not shut-off or remove!". Is a License Key required for the Full version of SQL# to work?
No. The only dependencies outside of the installation script are: 1) installing into a version of Microsoft SQL Server 2005 or newer, and 2) having the ability to enable CLR Integration (enabling CLR is done automatically by the installation script, but certain environments prohibit CLR from being enabled, and having the server option of “Lightweight Pooling” enabled also prevents CLR from being enabled, though it is rare that anyone even uses that option). Requiring a License Key would be an impediment to someone getting their job done, and the goal of Sql Quantum Lift is to provide tools that reduce complications, not add to them.
Is the Full version of SQL# licensed on a subscription model?
No. Once you have the software (either downloading the Free version, or purchasing and downloading the Full version) it is yours and will just work. The Full version does not require a License Key in order to function, and neither Free nor Full versions expire.
What is the License Key used for?
The License Key identifies each customer and is proof-of-purchase of the Full version of SQL#. It allows for:
Does SQL# work with SQL Server on Linux?
Yes, SQL# does indeed work with SQL Server on Linux (introduced in SQL Server 2017). The only restriction is that only SAFE Assemblies are allowed on Linux. Be sure to set the
@MaxAllowedAccessLevel variable in the installation script to "1".
Does SQL# work with SQL Server 2017? Data Migration Assistant suggests that it might not be compatible.
Yes, SQL# does indeed work with SQL Server 2017. The new "CLR strict security" server-level configuration option (enabled by default) requires that all Assemblies, even those marked as
SAFE , be signed with a Certificate or Asymmetric Key, and have a corresponding signature-based Login that has been granted the UNSAFE ASSEMBLY permission. SQL# has met these conditions for many years now.Microsoft did provide an alternate method for Assemblies that are not signed, and that is to register them as “Trusted Assemblies”. Registering Assemblies as “trusted” is entirely unnecessary for Assemblies, such as all SQL# Assemblies, that meet the conditions noted above. And in fact, the “Trusted Assemblies” feature itself is entirely unncessary and should have never been released. Please see: SQLCLR vs. SQL Server 2017, Part 4: “Trusted Assemblies” – The Disappointment for details. How do I install SQL# on SQL Server 2017? I get an error.
The installer for SQL# 4.1 handles SQL Server 2017 properly. If you can, please upgrade to version 4.1. Otherwise, for SQL# versions prior to 4.1, you can do the following:
ALTER DATABASE [master] SET TRUSTWORTHY ON; GO -- execute SQL# install script ALTER DATABASE [master] SET TRUSTWORTHY OFF; GO Does SQL# work with Azure SQL Managed Instance?
Yes! In fact, most SQL# functionality appears to work on a Managed Instance, including functionality requiring either “External Access” or “Unrestricted” permissions. So far, only functionality that accesses the network appears to not work, though it is possible that the errors could be due to firewall and/or routing configuration (more testing might be needed). Testing was done using SQL# 4.2 on Azure SQL Managed Instance 15.0.2000.
The @MaxAllowedAccessLevel variable in the installation script can be left at the default value of "3".
Does SQL# work with Azure SQL Edge?
No. There is absolutely no support for any .NET / CLR-based functionality on Azure SQL Edge, including built-in functions such as:
AT TIME ZONE , COMPRESS , DECOMPRESS , and FORMAT .
|
|||||
Copyright © 2006-2024 Sql Quantum Lift, LLC. All rights reserved. |