Quantcast
Channel: .NET Framework inside SQL Server forum
Viewing all 780 articles
Browse latest View live

Unable to add the PresentationFramework assembly

$
0
0

Hello

I am in the process of creating a CLR Function. One of the assemblies that I need to use for my CLR function is the PresentationFramework assembly.

When I try to add the assembly to my SQL database I get the following error:

Create failed for SqlAssembly 'PresentationFramework'.

Assembly 'presentationcore, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35'. was not found in the SQL catalog.

I tried adding the assembly from the following location (this is the same location that I successfully added the PresentationCore assembly from):

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0

I have already added the PresentationCore assembly to SQL and when I query sys.assemblies I can see it there with the same version number and publickeytoken as specified in the error:

name principal_id assembly_id clr_name permission_set permission_set_desc is_visible create_date modify_date is_user_defined
PresentationCore 1 65592 presentationcore, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35, processorarchitecture=x863 UNSAFE_ACCESS 1 2013-06-14 14:39:00.213 2013-06-14 14:39:00.213 1

The version of SQL I am using is 10.50.1600.

Please can someone explain why SQL is throwing this exception and provide me with a solution.

Many thanks

Dan


Split String into Multiple Rows with Position ID

$
0
0

I am currently doing some research on data mining and my research data table are looks following

ID   Author  1    Ali,Ahmad,David,Kumar2    Aslam,Abid,John

Now i want to split comma separated name of authors into multiple rows with the position_ID For Example

ID         Author         Position_ID  1          Ali                 11          Ahmad               21          David               31          Kumar               42          Aslam               12          Shahzad             22          John                3

I have currently made a split function and the following query that can only splits the author column values into multiple row but cannot get the author position_ID in the string into a separate column. Please give me some advice.![enter image description here][1] Thanks in advance

CREATE Function [dbo].[SplitString]
(@List Varchar(Max), @Delimiter Char(1))
Returns @Items 
Table (Item Varchar(max))
As
Begin
Declare @Item Varchar(max), @Pos TinyInt
While Len(@List) > 0 
Begin
Set @Pos = CharIndex(@Delimiter, @List)
If @Pos = 0 Set @Pos = Len(@List) + 1 
Set @Item = Left(@List, @Pos - 1)
Insert @Items 
Select Ltrim(Rtrim(@Item))
Set @List = SubString(@List, @Pos + Len(@Delimiter), Len(@List))
End
Return
End

declare @TAB table (strg varchar(max),Research_ID bigint)
insert @TAB
select authors,Research_ID from Citation
Select S.item As [Authors],Research_ID
From @TAB T
Cross apply [dbo].[SplitString](T.strg,',') S;

ALTER ASSEMBLY and Continuous Integration

$
0
0

I have a small assembly of scalar SQL functions built in .NET that I've manually integrated to SQL Server with CREATE ASSEMBLY and then CREATE FUNCTION.  However, as part of my continuous integration and deploy process, I'd like to update the assembly with every build using ALTER ASSEMBLY.

I've already taken care to guard against an unchanged MvID in the SQL batch I execute to do the update, but whenever a new build runs (and the MvID apparently changes), I get the following error:

ALTER ASSEMBLY failed because the required method "Xxx" in type "Yyy" was not found with the same signature in the updated assembly.

But the signature hasn't changed!  The signature is still just "DateTime? Yyy(DateTime?)".

I've found very little information about this error in particular.  Any suggestions?

SQL Server Create data about time always get "0001/1/1 0:00:00"

$
0
0
In my ASP.NET project,there is a filed about time in a data table (SQL Server 2008).Its type is "datetime",default value "getdate()". It worked well. While I change the type ,and use "datetime2".I think it's a good idea. But when I debug,its value is always "0001/1/1 0:00:00". I do not know where is wrong.I hope someone can help me solve this problem. Thank you!( Sorry,my English is poor ;) ) 

AppDomain 2 (mssqlsystemresource.sys[runtime].1) unloaded.

$
0
0

I have seen these two in my sqlserver read error log:

AppDomain 2 (mssqlsystemresource.sys[runtime].1) is marked for unload due to common language runtime (CLR) or security data definition language (DDL) operations.
AppDomain 2 (mssqlsystemresource.sys[runtime].1) unloaded.

Please explain what is this?


Thanks

Debugging CLR stored procedure that calls a CLR function

$
0
0

I have a CLR function that returns a table.

That function is called from a CLR stored procedure.
selectData = "SELECT Col1, Col2, ... FROM myFunc(@sampleTimeStart, @sampleTimeEnd)"
using (SqlCommand sqlCommand = new SqlCommand(selectData, sqlConnection))
{
 sqlCommand.Parameters.Add("@sampleTimeStart", SqlDbType.DateTime).Value = sampleTimeStartUtc;
        sqlCommand.Parameters.Add("@sampleTimeEnd", SqlDbType.DateTime).Value = sampleTimeEndUtc;
        using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
        {
         if (sqlDataReader.HasRows)
                {
                  while (sqlDataReader.Read())
                        {

I have a breakpoint on the first line past sqlDataReader.Read()
But when the sqlCommand.ExecuteReader() line is executed, the Dynamic Transact-SQL tab is opened and the debugger stops in it waiting on F5.
It seems to be automatically stepping into it on nearly every row returned by the called CLR function  (I can see this by setting a breakpoint in the function's fillRow method).
The function returns over 250K rows; that means I can never get to my breakpoint after sqlDataReader.Read().

How can I keep it from stepping into the Dynamic Transact-SQL?  I want to run past it to my breakpoint.

Update:
I can hardcode parameters to reduce the size of the data the function returns.
The breakpoint after sqlDataReader.Read() still isn't hit but one after the using {sqlCommand .... } closing bracket is hit.
I know the code after sqlDataReader.Read() is read because I can evaluate the collection the code populates and see the correct number of rows.


Kevin Jones


 

Compatible SQLCLR version for various SQL server

$
0
0

Hi, I could not find any documentation on what SQL CLR version is supported on various SQL Servers.

We have a project which uses CLRs stored procedures and is expected to support almost all SQL Servers starting from SQL Server 2005 Express (Including  SQL Server 2012 - 32 & 64 bit).

Can someone provide that information or point to the resource where I can find that information?

Any help is appreciated.

Thanks.

CLR SQL function returning nvarchar max shows null reference exception.

$
0
0

Hi,

I have created a CLR sql function with return type as varchar(max) using the following code.

<Microsoft.SqlServer.Server.SqlFunction()> _
    Public Shared Function Read123() As <SqlFacet(MaxSize:=-1)> String

When I run this on an SQL 2005 server it returned 90000 characters but when I deployed the code on SQL server 2008R2 it shows the following exception

Msg 6522, Level 16, State 1, Procedure Read123, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "Read123":
System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException:
   at System.Data.SqlServer.Internal.ClrLevelContext.GetCurrentContextForLobAccess(CClrLobContext* pLobContext)
   at System.Data.SqlServer.Internal.ClrLevelContext.GetXvarWlobStream(CXVariantBase* pxvarSource, XvarLOBStreamInitCode eCode, Int64 lcid, SqlCompareOptions compareOpts, CClrLobContext* pLobContext)

While calling from the query window.

If I remove the SqlFacet maxsize from the code, the above error will go but I wont be able to return a larger string (>8000chars). Is it due to any setting problem in SQL server 2008R2? Please Help.


WindowsImpersonationContext - how to get current SQL user in CLR function

$
0
0

Hi Folks,

I have a SQL CLR function that needs to call an external application.  The database has SET Trustworthy=ON, and the CLR function is being called as an UNSAFE assembly.

I am executing a call to the function in T-SQL as follows:-

EXECUTE AS LOGIN = 'x\some_user'
    SELECT SUSER_NAME()    -- returns  x\some_user
    SELECT * FROM [dbo].[udfSomeFunction]
REVERT

In order to do the impersonation I need to get the credentials for the current user (SUSER_NAME), not the service account that SQL Server is running under.

Inside the CLR function I am picking up the SQLContext.WindowsIdentity however it is always returning NT Service\MSSQLSERVER.  I have also tried using Environment.UserName but this also returns MSSQLServer.   I have tried creating the user defined function using the 'WITH EXECUTE AS CALLER' but it appears to make no difference.

Does anyone have any ideas on how to go about getting the correct credentials from within the CLR function using C#?

Regards

Andy

sql stored procedure and static block of data

$
0
0

Hi,

My stored procedure is built in C# and deployed to SQL server as a dll.

So I thought there should be some DLL initialization routine that runs at startup to initializa the DLL.

What I need to do is populate a very large table of static constant data. This table is used to decode binary blocks of data that are passed to the stored procedure.  It needs only be created once, then be available when the stored procedure is subsequently called.

In a simplified example, I thought something like the following code should be do-able:

public partial class StoredProcedures
{
    public static int[][] itable = new int[3][];
    itable[0] = new int[3];
    itable[1] = new int[3];
    itable[2] = new int[3];
    itable[0][0] = 1;
    itable[0][1] = 2;
    itable[0][2] = 3;
    itable[1][0] = 4;
    itable[1][1] = 5;
    itable[1][2] = 6;
    itable[2][0] = 7;
    itable[2][1] = 8;
    itable[2][2] = 9;
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void vciCreatePointCS
        (
        String acPointType,
        String acPointName,
        String acVECName
        )
    {

stored procedure vciCreatePointCS would then use the table without having to execute the "new" function on every call nor populate the table with data.

But the example above does not compile.

Can this be done?

Boyd


BDM

SQL Server Common Language Run-time Integration for Visual Studio 2012

$
0
0
Is there currently no SQL Server CLR Integration for VS 2012? The MSDN article refers to VS 2010 only. It looks like I will have to install VS 2010 alongside VS 2012 then.

CREATE ASSEMBLY failed because it could not open the physical file (The device is not ready.).

$
0
0

I have a simple class libarray that I have compiled into DLL using csc.exe

Source code is as follows: -

 

using

System;

using

System.Collections.Generic;

using

System.Text;

using

System.IO;

using

Microsoft.SqlServer.Server;

 

namespace

RTFTextParser

{

publicclassParseText

{

[

SqlFunction(DataAccess = DataAccessKind.None)]

publicstaticString ParseRTFText()

{

return"Imtiaz";

}

}

}

When I try to run the following

CREATE

ASSEMBLY RTFTextParser FROM'E:\Class1.dll'

 I get the following error

Msg 6501, Level 16, State 7, Line 1

CREATE ASSEMBLY failed because it could not open the physical file 'E:\Class1.dll': 21(The device is not ready.).

 

Generating pdf files from inside the db

$
0
0

I would like to investigate performance and difficulties related to generating

pdf files using a .Net CLR procedure.

Assume a situation where you have all data needed for pdf inside the db, it could be interesting

to generate pdf inside db without having to use seperate (SSRS) server.

For a situation like this I was tempted to use itextsharp.dll from http://sourceforge.net/projects/itextsharp/files/latest/download

But the first obstacles already arises before I try to write my CLR proc when trying to load the

DLL into db:

1.) Using SSMS, right clicking "Assemblies" to get the "New Assembly"-GUI, typing in the path to assembly and choosing "Permission set"=Unrestricted

I got:

TITLE: Microsoft SQL Server Management Studio

Createfailed forSqlAssembly 'itextsharp'. (Microsoft.SqlServer.Smo)

For help,click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.3000.0+((SQL11_PCU_Main).121019-1322+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+SqlAssembly&LinkId=20476

ADDITIONAL INFORMATION:

An exceptionoccurredwhileexecuting aTransact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

Assembly 'system.drawing, version=2.0.0.0, culture=neutral,publickeytoken=b03f5f7f11d50a3a.'was notfound in the SQLcatalog. (Microsoft SQL Server,Error: 6503)

For help,click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=11.00.2100&EvtSrc=MSSQLServer&EvtID=6503&LinkId=20476

2.) I also tried in SSMS:


CREATE  ASSEMBLY itextsharp
 FROM  'C:\...\PDFGenerator\PDFGenerator\bin\Debug\itextsharp.dll'
 WITH  PERMISSION_SET = UNSAFE;

Msg 10301, Level 16, State 1, Line 1
Assembly 'itextsharp' 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(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

======

Seems the 2. approach results in more informative error message;

but it says "Please load the referenced assembly...", isn't that what I actually have tried?

Is it suggestiong to do what I have tried to do??

I also tried this, but it didn't help either:

execute sp_configure 'show advanced options', 1;
GO
RECONFIGURE
go


execute sp_configure  'clr enabled', 1;
GO
 
RECONFIGURE
go



alter database bdj SET TRUSTWORTHY ON;


use master;

CREATE ASYMMETRIC KEY asymmetrickey1 FROM EXECUTABLE FILE = 'C:\...PDFgenerator\PDFGenerator\PDFGenerator\bin\Debug\itextsharp.dll' ;



CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY asymmetrickey1;
 
GRANT  UNSAFE ASSEMBLY TO CLRLogin --GRANT EXTERNAL ACCESS ASSEMBLY TO SQLCLRTestLogin 


use bdj;


CREATE  ASSEMBLY itextsharp
 FROM  'C:\...\PDFgenerator\PDFGenerator\PDFGenerator\bin\Debug\itextsharp.dll'
 WITH  PERMISSION_SET = UNSAFE;

Any suggestions on how to solve this?


B. D. Jensen

A question about Microsoft.SqlServer.SqlParser.dll

$
0
0

Hi all,

I found this library in SSMS 2008 assemblies, it can parse T-SQL statements into structured XML as well. 
'Microsoft.SqlServer.SqlParser.Parser.Parser.Parse(SQL)'
This function can resolve standard select/update/insert statements, and it's very useful to us for advance code policies check,  but it's not for all sql commands, for example: 'CREATE TABLE' is okay to go, but 'ALTER TABLE' is not. why?
And one thing more, after SQL Server 2008 R2 is installed, this assembly disappeared.:(

Is it a half-done job?
Where can I find the final version?

CLR SP sometimes raises severe error

$
0
0

I have pretty complex CLR stored procedure which opens external connections and calls T-SQL procedures to read and update data.

Usually it works fine but sometimes it raises error: “A severe error occurred on the current command. The results, if any, should be discarded.” I do nothing just run it again few times and finally it successfully finished.

What can be cause of this behavior? What can I dig to find root of issue?

Can internal usage of OPENXML be issue? Or maybe transactions? 

I’m on SQL Server 2008R2 Enterprise 64-bit. 



Join Microsoft -- China-Beijing

$
0
0

Microsoft IT

Making IT happen. Improving the way people work is our daily motivation. We start with the best talent and add leading process and information technologies to engineer IT solutions for employees worldwide. Our goal is to make it as easy as possible for them to create and deliver the new products and services that will drive our company's ongoing business success. Here at Microsoft IT, we help change the way the world lives, works and plays. Explore our job opportunities and, if you like what you see, consider joining us—our people are some of the most extraordinary people you’ll ever meet.

Microsoft IT China

Delivers IT solutions and services that drive innovation and business values. MSIT China Engineering group is a strategic engineering delivery center established in Beijing in 2007.  Our mission is to enable Real-Time Enterprise IT and achieve customer delight via evangelizing Microsoft forward looking technologies, reliably delivering IT engineering solutions, and contributing to MS China market growth with showcase IT.

In MSIT China, you have the opportunity to work with various business stakeholders and engineers to deliver the breakthrough solutions that help to connect the company, delight the customers and inspire the industry.

Our end to end solution portfolios cover Business Intelligence, Dynamics CRM platforms & solutions, large scale web platform development onwww.microsoft.com in Search, Mobile and Download center, Enterprise platform & Services, SharePoint in Cloud, Corporate social network, Mobile workplace. We are looking for passionate talents to join us to deliver the world class enterprise IT solutions.

Positions

BI Sr Dev Lead-MSIT-China-Beijing

https://careers.microsoft.com/jobdetails.aspx?ss=&pg=0&so=&rw=1&jid=110595&jlang=EN&pp=SS

SDEII-MSIT-China-Beijing

https://careers.microsoft.com/jobdetails.aspx?ss=&pg=0&so=&rw=1&jid=106509&jlang=EN&pp=SS

SDEII-MSIT-China-Beijing

https://careers.microsoft.com/jobdetails.aspx?ss=&pg=0&so=&rw=1&jid=110594&jlang=EN&pp=SS

SDET II-MSI-China-Beijing

https://careers.microsoft.com/jobdetails.aspx?ss=&pg=0&so=&rw=1&jid=107059&jlang=EN&pp=SS

SDET II-MSIT-China-Beijing

https://careers.microsoft.com/jobdetails.aspx?ss=&pg=0&so=&rw=1&jid=111738&jlang=EN&pp=SS

SE-MSIT-China-Beijing

https://careers.microsoft.com/jobdetails.aspx?ss=&pg=0&so=&rw=1&jid=111739&jlang=EN&pp=SS

Regards,

Netty

Office: +8610 5917-4462| Mobile: +86139 1013-0105 | MSN:lovezhangaili@msn.com

To find out more about MSIT positions, click here!

clr function with error A .NET Framework error occurred during execution of user-defined routine or aggregate "funAFTN_GetFilesFromDirectory": System.IO.IOException: Logon failure: unknown user name or bad password.

$
0
0

hi

i create a .dll in asp.net and it shoud read files on network

when i use it in asp it works well and can read all files from network

and i can read files from network in sql too

but when i call that .dll  in sql (clr func) it dosnt work and error

Msg 6522, Level 16, State 1, Line 19
A .NET Framework error occurred during execution of user-defined routine or aggregate "funAFTN_GetFilesFromDirectory":
System.IO.IOException: Logon failure: unknown user name or bad password.

System.IO.IOException:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOption searchOption)
   at ReadFiles_AFTN.ReadFiles_.GetFilesFromDirectory(String number)

why?

Also i can call clr function by read files from drive C and work well

this problem occure when i use network address in class library

please help me

asp.net with .net 2 ,  sqlserver 2012

i try it by .net 4 and dosnt work:(

Unable to load System.IdentityModel.dll assembly into SQL Server 2012

$
0
0

Hello,

I try to load an assembly which refers to 'System.IdentityModel.dll' (because it uses WCF) into SQL Server 2012 Express 64Bit.

I get always this error message:

Msg 6544, Level 16, State 1, Line 41

CREATE ASSEMBLY for assembly 'System.ServiceModel'

failed because assembly 'microsoft.visualbasic.activities.compiler' is malformed or not a pure .NET assembly.

Unverifiable PE Header/native stub.Msg 10301, Level 16, State 1, Line 42Assembly 'SQL2012OPCFunctions' references

assembly 'system.servicemodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.', 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(The system cannot find the file specified.)). Please load the referenced assembly into the current

database and retry your request.

I use to load the assembly from this path: ''C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\System.ServiceModel.dll''

All other referenced assemblies are loaded without any problem.

The assembly worked already under SQL server 2008 R2 64Bit.

Has anyone an idea how to solve this problem?

Could not Load File or Assembly 'Microsoft.sqlserver.connectioninfo, version 10.0.0.0, culture:neutral, publickeytoken:*string number*

$
0
0

I keep getting this error whenever I try to make a table for a local database in Visual C# Express. I'm trying to make a Windows Form Application following a book called 'Headfirst C#', I'm making a application to store 'contacts' in and when I try to make a table I get this.

C# is the first programming I'm trying to learn and this has been in my way for a few days now. I've been searching all over the web but haven't found anything. (Not even in /WINDOWS/ASSEMBLY where apparently there are files that need changing?)

I have Microsoft Framework 4 Client Profile/Extended/Multi-Targeting Pack

Microsoft SQL Server compact 3.5 SP2

Microsoft SQL Server 2008 R2 setup.

Different version in GAC and SQL

$
0
0

I have imported .NET 2.0 assemblies into SQL server.
Everything worked. I haven't install anything to GAC.

Then somebody has installed the new version of microsoft.net 4.0.
Now there are different version of NET assemblies in GAC than in SQL server.
Here is error and solution:
http://support.microsoft.com/kb/949080

If I ALTER assembly to new .NET dll's, than it won't work since SQL supports only up to NET 3.5 version.

I guess that I have to install also old SQL assemblies into GAC or something.
What would be solution?

When I add the assembly it copies it into the database.  When your SQLCLR code goes to load the assembly it checks the MVID against the one in the GAC, if they are different it refuses to load. Is there a way to say SQL - don't check assembly in GAC, use the one you have in database.
Otherwise, everytime when someone install a newer dll, there will be a problem.

Thanks,Simon


Viewing all 780 articles
Browse latest View live