I have a program that is intensive in CRUD operations on a SQL Server Express 2012 database. I was hoping to create a CLR assembly that contained most of the code and then attach it to the database so that it would stay on the server. I was hoping to have resource-intensive calculations performed on each row in a specific table and then the results from this calculation will be entered into a column (not involved in the calculation itself) in that table. I wanted this to stay on the server so that the server could automatically do the calculations without the front-end application having to call it, and without the application having to submit TSQL back and forth from the server. I also wanted to write the code in VB.NET using Entity Framework to make things easier.
Before I wrote the real program, I decided to try this approach using AdventureWorks2012. I created a class library in Visual Studio, then built in in Release mode. I then went into SQL Server Management Studio, right-clicked the Databases > AdventureWorks2012 > Programmability > Assemblies node, and clicked "New Assembly...", I navigated to my built DLL and clicked OK, but SQL Server Management Studio gave me this error message:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for SqlAssembly 'AdventureWorks_01'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.5058.0+((SQL11_PCU_Main).140514-1820+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+SqlAssembly&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Assembly 'entityframework, version=6.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' was not found in the SQL catalog. (Microsoft SQL Server, Error: 6503)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=11.00.5058&EvtSrc=MSSQLServer&EvtID=6503&LinkId=20476
------------------------------
I noticed that this asked for an entityframework
assembly, and there was one in the build folder, so I tried to add it using the same method, but I get this error message:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for SqlAssembly 'EntityFramework'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.5058.0+((SQL11_PCU_Main).140514-1820+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+SqlAssembly&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
Assembly 'system.runtime.serialization, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' was not found in the SQL catalog.
Warning: The Microsoft .NET Framework assembly 'entityframework, version=6.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details. (Microsoft SQL Server, Error: 6503)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=11.00.5058&EvtSrc=MSSQLServer&EvtID=6503&LinkId=20476
------------------------------
I also saw a DLL named EntityFramework.SqlServer.dll
in the folder, so I tried to add it, but it produced the first error message.
Here is my VB code:
Public Class Class1
Sub AddNewProduct()
Dim adWorks As New AdventureWorks2012Entities()
Dim myProduct = New Product()
With myProduct
'add applicable product info here
End With
adWorks.Products.Add(myProduct)
End Sub
End Class
Does anyone know how I can fix this problem, or if I can add Entity Framework CLR assemblies to an SQL Server database in the first place?