I have followed the steps outlined in the knowledge base article http://support.microsoft.com/kb/913668 for effecting Xml Serialization within the SQL CLR. That is, I have
1. Prebuilt the serialization assembly X.Serializers for the types in assembly X and,
2. Registered both assemblies with SQL Server via the create assembly directive
Yet, when I attempt to create an XmlSerializer on the basis of one of the types defined in X, SQL CLR ignores the pre-built serialization assembly and attempts to dynamically create/load the assembly. Since dynamic loading is disallowed, this fails with the expected exception:
System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments assembly load functionality is restricted, consider using pre-generated serializer. Please see inner exception for more information. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.
I have followed the steps outlined in the knowledge base article http://support.microsoft.com/kb/913668 for effecting Xml Serialization within the SQL CLR. That is, I have
1. Prebuilt the serialization assembly X.Serializers for the types in assembly X via the SGEN tool and,
2. Registered both assemblies with SQL Server via the create assembly directive
Yet, when I attempt to create an XmlSerializer on the basis of one of the types defined in X, SQL CLR ignores the pre-built serialization assembly and attempts to dynamically create/load the assembly. Since dynamic loading is disallowed, this fails with the expected exception:
System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments assembly load functionality is restricted, consider using pre-generated serializer. Please see inner exception for more information. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.
I made a point type by C# for deploying in SQL2005.
It builds successfully every time.
When I deploy, it gives the following error: "Error: Type "SqlServerProject1.TypePoint" is marked for native serialization, but field "x" of type "SqlServerProject1.TypePoint" is not valid for native serialization." although x variable is value type decimal.
using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server;
Hello,I am trying to serialize (binary) a class and save it in a database. I followed a few examples I found in internet and this is what I came up with: 1 ' Rows 2 <Serializable()> _ 3 Public Class Rows 4 Implements ISerializable 5 6 Private _Rows As New Generic.List(Of Row) 7 Public Property Rows() As Generic.List(Of Row) 8 Get 9 Return _Rows 10 End Get 11 Set(ByVal value As Generic.List(Of Row)) 12 _Rows = value 13 End Set 14 End Property ' Rows 15 16 ' New 17 Public Sub New() 18 End Sub ' New 19 20 ' New 21 Public Sub New(ByVal siRows As SerializationInfo, ByVal scRows As StreamingContext) 22 End Sub ' New 23 24 ' GetObjectData 25 Public Sub GetObjectData(ByVal siRows As SerializationInfo, ByVal scRows As StreamingContext) Implements ISerializable.GetObjectData 26 27 siRows.AddValue("Rows", Me.Rows) 28 29 End Sub ' GetObjectData 30 31 Public Sub Serialize(ByVal filename As String) 32 33 Dim sRows As Stream = Stream.Null 34 Try 35 sRows = File.Open(filename, FileMode.Create, FileAccess.ReadWrite) 36 Dim bfRows As New BinaryFormatter 37 bfRows.Serialize(sRows, Me) 38 Finally 39 sRows.Close() 40 End Try 41 42 End Sub ' Serialize 43 44 Public Shared Function Deserialize(ByVal filename As String) As Rows 45 46 Dim sRows As Stream = Stream.Null 47 Try 48 sRows = File.Open(filename, FileMode.Open, FileAccess.Read) 49 Dim bfRows As New BinaryFormatter 50 Return CType(bfRows.Deserialize(sRows), Rows) 51 Finally 52 sRows.Close() 53 End Try 54 55 End Function ' Deserialize 56 57 End Class ' Rows After serializing the class I need to save it in an a SQL 2005 database.But all the examples I followed use the filename ... Anyway, do I need to do something to save this into an SQL 2005 database or can I use it as follows? And how can I use this?This is the first time I do something like this so I am a little bit confused.Thanks,Miguel
I have a C# application that get data (i.e. select Firstname, LastName from person) to form a DataSet object (i.e. PersonName variable inside my code). Then I want to post this DataSet object into a local private queue (the path is: .privatemyTestQ). Note that I carefully labled the message to be "Variables Message" (as needed per anothre thread discussion here in this forum).
I created a receiving package, in which I want to use SSIS's Message Queue task to retreive the above DataSet object (from C# application). I got failure:
[Message Queue Task] Error: An error occurred with the following error message: "Root element is missing.".
However, As a comparison research, I created another SSIS sending-package. And I used ADO.NET provider to get the same data to store the sull result set in a package-level variable. Then I use Message Queue task to post this variable (i.e. object) to the same private queue above. Then I run my above receiving package. I was successful to read back the messge that I posted from SSIS sending package. (Please note that if I use OLEDB provider for sending package to get data from database, the MSMQ task for sending failed due to serializtion issue for __ComObject. With ADO.NET provider, the result set is represented as a type of DataSet).
I then curiously looked into message body from Computer Management Counsol. I found that message sent from SSIS is in SOAP format while message from my C# application is NOT in SOAP (but only in XML format). Obviously SSIS MSMQ task serialize objects into SOAP format.
Can anyone here please help on how to serialize my DataSet object from my C# app) in compliance with the MSMQ task's spec so that I can read message from Q using SSIS package.
So it means that this class will be serialized in the native SQL Server format. Is there any possibility to deserialize data retrieved from server as bytes to an object instance? For example:
while (rdr.Read()) { // Retrieve the raw bytes into a byte array byte[] buffer = new byte[32]; long byteCount = rdr.GetBytes(1, 0, buffer, 0, 32); Point pt = new Point(); // Here I need to fill the created object with retrieved data }
After I retrieved the data in bytes format, I need to write it to the object. How can I do this? In fact, I have no possibility to use SqlDataReader in the following manner:
Code Snippet // Retrieve the value of the UDT Point pnt = (Point)rdr[1]; // Point pnt = (Point)rdr.GetSqlValue(1); // Point pnt = (Point)rdr.GetValue(1);
because I retrieve data in bytes not from the server, but from an unmanaged application. I have a possibility to create an instance of the class, but how can I fill this instance with data? Is it possible to do using native SQL Server native format? How can I do this when UDT uses user defined serialization?
I have started to see regular occurences of "ODBC error 40001- serialization failure" in the log of a client website (using cold fusion) and would be grateful for any suggestions on likely causes and solutions. The error message also mentions deadlock victims. Thank you in advance.
I am getting the following error when executing a CLR stored procedure. I have set generate serialization assembly to 'ON' with no effect. The error is:
System.InvalidOperationException: Cannot load dynamically generated serialization assembly. In some hosting environments assembly load functionality is restricted, consider using pre-generated serializer. Please see inner exception for more information. ---> System.IO.FileLoadException: LoadFrom(), LoadFile(), Load(byte[]) and LoadModule() have been disabled by the host.
24.121.0.118, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322), ODBC Error Code = 40001 (Serialization failure) [Microsoft][ODBC SQL Server Driver][SQL Server]Transaction (Process ID 56) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Any ideas? Would setting the isolation level to Read Commited help?
In article http://support.microsoft.com/kb/913668 it says to generate a serialization assembly and pop this into the database along side the assembly with the serialized type. All well and good, but how doe the XmlSerializer know to look in the database for the assembly - does it use the name of the assembly + XmlSerializer?
It is certainly ambiguous in the aforementioned kb article. In one place it generates an assembly in the database called
CREATE ASSEMBLY [MyTest.XmlSerializers] from 'C:CLRTestMyTestMyTestinDebugMyTest.XmlSerializers.dll' WITH permission_set = SAFE
and in another it uses
USE dbTest GO CREATE ASSEMBLY [MyTest] from 'C:CLRTestMyTest.dll' GO CREATE ASSEMBLY [MyTest.XmlSerializers.dll] from 'C:CLRTestMyTest.XmlSerializers.dll' GO
I can't get either to work, and I've tried various combinations, this and the fact that the kb artice uses two different naming conventions suggests to me that there must be "something else" which links the assembly with the serialization assembly.
I wrote an assembly and attached to a trigger in one of my tables. It works as I expected, but then I decided to modify the code, say adding some new triggers that I will use with other tables. Then I realize that in order to update my new version of the assembly in SQL first I need to remove the trigger in the table, then remove the assembly, add the new version and finally run a script to create the trigger again in the table.
How could I avoid going through all this process everytime I want to update my assembly?
I am running a CLR stored proc that goes to an EDS (Novell) server with LDAP and returns records into a SQL table.
I am using the Novell ldap library.
I want to do this with SSL so my code referneces the Mono security library as well.
However when I make the call to the stored proc to run in SSL, I get an object not found error. I do not think that the the Novell assembly can "find" the Mono assembly.
Two points: 1/ I can do the SSL if I run it as an asp.net page (so I know the SSL works) 2/ The proc runs and pulls all the records in non-SSL (so I know the proc works)
i found one tutorial on self signing assemblies for use in sql server, but it appears to have errors. does anyone know of a better tutorial on this topic? the site im currently looking at is here: http://www.sqljunkies.com/WebLog/ktegels/articles/SigningSQLCLRAssemblies.aspx
I have a question: how is it planned to replicate changes made to the assemblies and to the CLR functions or UDT? Will Visual Studio deploy change of the Assembly as ALTER not DROP/CREATE?
How does SQL Server 2005 handle the replication of assemblies? I get the following when trying to replicate an assembly:
Timestamp: 6/15/2007 9:41:33 AM Message: HandlingInstanceID: 05eaed53-b6be-42da-8c72-0f91fcbfa5b6 An exception of type 'Microsoft.SqlServer.Replication.ComErrorException' occurred and was caught. ------------------------------------------------------------------------------------------------- 06/15/2007 09:41:33 Type : Microsoft.SqlServer.Replication.ComErrorException, Microsoft.SqlServer.Replication, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 Message : The schema script 'StratisDSonetd85d6e89_1061.sch' could not be propagated to the subscriber. Source : Merge Replication Provider Help link : ErrorMessage : Unspecified error InterfaceId : 00000000-0000-0000-0000-000000000000 HelpFile : HelpContext : 0 Description : The schema script 'StratisDSonetd85d6e89_1061.sch' could not be propagated to the subscriber. ComHResult : -2147467259 ErrorCode : -2147467259 Data : System.Collections.ListDictionaryInternal TargetSite : Void Run() Stack Trace : at Microsoft.SqlServer.Replication.MergeSynchronizationAgent.Run() at Microsoft.SqlServer.Replication.MergeSynchronizationAgent.Synchronize() at SQLClientSync.SQLClientSync.Replicate() Additional Info: MachineName : REPCLIENT TimeStamp : 6/15/2007 1:41:33 PM FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=1.1.1.1, Culture=neutral, PublicKeyToken=d2ff10320a77ec18 AppDomainName : sqlclientsync.exe ThreadIdentity : WindowsIdentity : REPCLIENTAdministrator
I appears that the initial replication of the assembly was fine, when re-running the sync (no changes to the assembly), this error is generated.
I need to dynamically create a ADO.NET connection manger
so, my question is if it is safe to create it with the string that is generated (ConnectionManagerType) when creating the connection manager manually on my PC.
I understood that this string is the full qualified name of the assembly, so will it be different when I create it on another P.C or it is fixed on all P.Cs ?
Where is it documented what the list of approved assemblies are for SQL 2005. Also, is there a way via T-SQL, or other means to get it programatically?
I'm building a SQL function from C++ and compile my assembly with /clrafe. After that I create the assembly with SAFE permission sets and create the function, both in SQL. But the server don't accept load or execute the function because of permission error. It says:
Code Snippet
"An error occurred in the Microsoft .NET Framework while trying to load assembly id 65561. The server may be running out of resources, or the assembly may not be trusted with PERMISSIONSET = EXTERNALACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues."
Does the terminology coince with the technology, or is it diffrent "safety" conditions we are speaking about? One for the SQL permission set, and another safety for CLR type-safe assemblies?
Anyway, after playing around a bit, and following the tricks from this thread. I managed to load and execute the function, but only in UNSAFE permission (unrestricted mode?)
---8<----
My second question is can I use unrestricted mode for assembly compiled with /clr (mixed CLR)?
I'm asking, because I have some C source code that I want to reuse, and for this I can't be type-safe and therefore need to compile only with /clr (mixed CLR).
Should I go back to the plain C API in SQL 2000 to implement such function in SQL 2005, and ignore all new things in c++/CLR/.NET?
If you have any points to C++ sample code, then please forward this to me.
Did this as a exercise and am fed up with my fruitless searching.Went and create an CLR assembly and all with min hassel. Now that Ihave that dll out there, I am tring to find some system table or somedisplay in management studio that shows me where the file is located onthe hard drive and cannot locate it.Can someone please point me in the correct location.Thanks.
I am trying to load multiple strongly named assemblies into the same database which are signed with the same .snk file (signed in Visual Studio). I use the following code to create an asymmetric key and login as Books Online recommends:
CREATE ASYMMETRIC KEY SQLCLRKey FROM FILE = 'D:dbainAssembly.dll'
CREATE LOGIN CLRAssembler FROM ASYMMETRIC KEY SQLCLRKey
GRANT UNSAFE ASSEMBLY TO CLRAssembler
GRANT EXTERNAL ACCESS ASSEMBLY TO CLRAssembler
REVOKE CONNECT SQL FROM CLRAssembler
Do I need to create a new login and asymmetric key for each assembly I load? If so, do I need to sign each with a different key because its giving me an error message when I try to create 2 separate asymmetric keys/logins from 2 different assemblies which have been signed with the same .snk file.
The only way I've gotten everything to load properly is to create a separate key for each assembly and sign each, then create separate logins and asymmetric keys in the database.
Is this the only way to do this? Or am I missing something?
To set up a managed sproc to act as a WSE 3.0 web service client I had to register the following .Net DLLs as UNSAFE assemblies: System.Configuration.Install.dll System.Web.dll Microsoft.Web.Services3.dll
In order to register UNSAFE assemblies I had to set the database's TRUSTWORTHY property to 'true'.
Can anyone tell me what are the implications of doing this?
Hi,I have developed a Stored procedure to output text to a text file, after doing a lot of reading here. I want to be able to output data to a Postgres database, to be used for web mapping. I have referenced an Assembly Npgsql.dll so I can send updates to the postgres database when my ms sql database is updated. However, after building my class library, when I try to CREATE ASSEMBLY in sql server 2005 express, it sends out a message: Msg 10301, Level 16, State 1, Line 1 Assembly 'ClassLibrary1' references assembly 'system.drawing, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(error not found)). Please load the referenced assembly into the current database and retry your request. The error seems to be in the Npgsql.dll assembly, can anybody please shed some light on this. I tried to load the system.drawing assembly, and can do so in Unrestricted mode. It then spits out the same problem for System.Windows.Forms.dll. I am still very new to all of this so any help would be appreciated. Cheers, Jatz91.
Throughout the course of this book and even before it I have come across conflicting information regarding how SQLCLR attempts to resolve system/CLR assembly references. For example, prior to my latest read thourgh April BOL 2005, I thought SQLCLR attempted to resolve these references implicity for you via the local machine's GAC. Yet here is what I found while trying to help another person in this forum yesterday in BOL... Assembly Validation SQL Server performs checks on the assembly binaries uploaded by the CREATE ASSEMBLY statement to guarantee the following:
The assembly binary is well formed with valid metadata and code segments, and the code segments have valid Microsoft Intermediate language (MSIL) instructions.
The set of system assemblies it references is one of the following supported assemblies in SQL Server: Microsoft.Visualbasic.dll, Mscorlib.dll, System.Data.dll, System.dll, System.Xml.dll, Microsoft.Visualc.dll, Custommarshallers.dll, System.Security.dll, System.Web.Services.dll, and System.Data.SqlXml.dll. Other system assemblies can be referenced, but they must be explicitly registered in the database.
For assemblies created by using SAFE or EXTERNAL ACCESS permission sets:
The assembly code should be type-safe. Type safety is established by running the common language runtime verifier against the assembly.
The assembly should not contain any static data members in its classes unless they are marked as read-only.
The classes in the assembly cannot contain finalizer methods.
The classes or methods of the assembly should be annotated only with allowed code attributes. For more information, see Custom Attributes for CLR Routines.
Besides the previous checks that are performed when CREATE ASSEMBLY executes, there are additional checks that are performed at execution time of the code in the assembly:
Calling certain Microsoft .NET Framework APIs that require a specific Code Access Permission may fail if the permission set of the assembly does not include that permission.
For SAFE and EXTERNAL_ACCESS assemblies, any attempt to call .NET Framework APIs that are annotated with certain HostProtectionAttributes will fail.
COULD SOMEONE PLEASE GIVE ME THE DEFENITE ANSWER ON HOW THIS WORKS!
I have a mixed CLR assembly (including native C++ and manage C++). Can I use this assembly in SQL SERVER 2005 or 2008? I know pure managed assemblies work fine. Thanks.