Suppose I have a simple C # code to print HELLO WORLD as shown here
using System; using System.Data; using Microsoft.SqlServer.Server; using System.Data.SqlTypes; public class HelloWorldProc { [Microsoft.SqlServer.Server.SqlProcedure] public static void HelloWorld() { SqlContext.Pipe.Send("HELLO WORLD!\n"); } }
Therefore they say on this page:
This section provides an overview of the namespace and libraries required to compile database objects using Microsoft SQL Server Integration with the Microsoft.NET Framework (CLR). The topic also shows how to write, compile and follow a simple CLR storage procedure written in Microsoft Visual C #.
CLR integration functionality is exposed in an assembly called system.data.dll, which is part of the .NET Framework. This assembly can be found in the global assembly cache (GAC), as well as in the .NET Framework directory. A reference to this assembly is usually added automatically by both tool commands and Microsoft Visual Studio, so there is no need to add it manually.
After creating (compiling and adding to the dll path), you can use this code as a stored procedure, for example:
CREATE ASSEMBLY helloworld from 'c:\helloworld.dll' WITH PERMISSION_SET = SAFE
Once the assembly has been created, we can now access our HelloWorld method using the create procedure statement. We will call our stored procedure "hello":
CREATE PROCEDURE hello AS EXTERNAL NAME helloworld.HelloWorldProc.HelloWorld
Once a procedure has been created, it can be started as a regular stored procedure written in Transact-SQL. Run the following command:
EXEC hello
To remove this proc:
drop procedure hello
Once the procedure has been deleted, you can delete the assembly containing your sample code.
drop assembly helloworld
After this introduction:
I need to use C ++ code that also uses extern dll, and my question is this:
How could I use my C ++ code (which also uses extern dll) inside this C #, as in the example, so after creating the assembly I am currently executing the saved process, the following is transparent:
- SQL creates the assembly and then calls the C # code inside the dll.
- C # code calls C ++ code (inside dll)
- C ++ code calls extern dll.
Therefore i only do
EXEC hello
and everything that happens (SQL SERVER -> C # -> C ++ -> extern dll).
- How to make this whole dll page continue and coexist, so I only execute the stored procedure on SQL Server, for example EXEC hi
I thought in
[DllImport("cCode.dll")]
but if C ++ code depends on exll dll ... I get lost