We're using MSMQ to insert records from a service into SQL Server tables in multiple locations. I'd like to insert into this MSMQ queue from SQL Server - that way, rather than come up with my own way to add messages to each server, I can just piggyback on the existing infrastructure and code.
It looks like the best way to do this is by using a CLR.
However, all the code I've found to create MSMQ messages from a CLR require UNSAFE mode. Is there a way to do it in EXTERNAL_ACCESS mode instead?
This is most likely because System.Messaging is not a supported library for CLR. Since it's not a supported library, it does not meet the requirements of SAFE or EXTERNAL_ACCESS.
Read more here: http://msdn.microsoft.com/en-us/library/ms403279.aspx
Related
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.
I want to use mysql proxy for processing queries trying to execute. I want to make this process available for all databases like mysql, ms sql server, oracle and ...
is it possible to use mysql proxy as base engine and connect these database from that? if no, is it possible to do this by making some little changes to mysql proxy source code?
You could use the standard external stored procedure support in the DBMS, but it would be difficult to map arbitrary queries to something meaningful.
Your are likely to be more successful implementing a lightweight parser as described in MySQL Client/Server Protocol and What communication protocol uses MySQL?.
Your preference that this can be done with 'some little changes' is likely not to be realistic. Expect a major job of the scale of ODBC to implement a generic SQL dialect translator.
I found that i have to use other exisiting proxies and change them in order to get what I need
I would like to use existing Delphi code to write SQL Server stored procedures.
In the past I used extended stored procedures, somehow a dll compiled by Delphi wrapped by a SQL Server extended stored procedure.
Extended stored procedures are now deprecated, so somehow I wonder if there is a solution, even in the "trick domain", like some sample CLR code that wraps a normal dll or something like that.
Just to give you an example:
I insert in the db some documents by encrypting them and I would like to create a kind of API based on SQL Server functions / procedures for inserting or reading documents, so other people accessing sql server can call those functions.
Of course an alternative solution is to use webservices but I would like to try the SQL Server way first.
Note: I don't want to use Delphi Prism, my code is for XE2.
Unsafe SQLCLR assemblies can p-invoke native dlls. A better way would be to expose the native DLL services as a COM interface and use COM interop from SQLCLR, or even call the COM APIs directly from SQL via OLE Automation Procedures. An even better way would be to rewrite the Delphi code as CLR code and invoke it directly as SQLCLR procedure. And the best way would be to use SQL Server native encryption features.
Not to mention the fact that CLR in SQL Server is a guaranteed deep performance hit. Keep to the standard CRUD operators and you should be fine. The other way to do it is to use the file system as your encryption mechanism. If you are only trying to prevent casual access to docs this is a fine way to go. Otherwise it might be time to rethink your access protocol.
CLR in SQL Server is a convenient bad idea. Use it sparingly if at all.
I am totally new to SQL Server CLR. I understand that we should use CLR under the condition that business logic is really complicated to implement in SQL.
We have quite a few functions in VB.NET to process data, such as standardizing data. I am trying to implement them through CLR. The functions access a remote server first to get some reference data, then process on the local server.
However no matter how I try, I got Error
System.NullReferenceException: Object reference not set to an instance of an object.
or it returns null from the remote server.
Can we access a remote server in the CLR routine? If yes, how?
You can access remote servers in the .Net CLR but you really shouldn't.
SQL server operates in a cooperative multitasking environment, i.e. threads are trusted to terminate and complete their processing (one way or another) in a timely manner. If you start doing things like calling remote methods (which are liable to long delays) you are likely going to end up starving SQL server worker threads which will ultimately end up with Bad Things happening.
Also see this question
Yes you can. You can use the normal SqlCommand & SqlConnection classes in the .NET framework to do so.=, if the remote servers are SQL Servers, which I assume it is.
If they are web servers, yes you can, use web services.
On a side note. Be very careful what you do in the CLR, because as attractive as CLR looks you only have about 512MB of memory under SQL 2005, and by adding some startup parameters you can push it out to 2Gb. Just be aware.
EDIT:
Based on your comments, I suggest using a linked server, and then re-creating the remote table locally and then joining to it on the local server.
You will have to make sure you re-create indexes and keys on the local box, and for speed -sake, do it after you inserted the records into the table, else building your indexes on an already populated table, will take a long time.
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.