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

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?

SQL Server 2008 R2: System.InvalidOperationException: Operation is not valid due to the current state of the object

$
0
0

The SSMS generate Scripts option (ALL OBJECTS - SINGLE FILE OPTION) was working fine.
Since few days its giving error on UDT generation:

System.InvalidOperationException: Operation is not valid due to the current state of the object. at Microsoft.SqlServer.Management.SqlScriptPublish.GeneratePublishPage.worker_DoWork(Object sender, DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument

1. I have deleted dependant objects and recreated UDT and then recreated dependant objects it worked okay once and then again started giving same error.

2. DBCC ran with no errors

3. If SSMS option of checking ALL individual object types is selected script runs successfully  -however the UDT is scripted at the bottom of the script and not before the dependant object.

Could it be issue with (KB2804576) which I installed few days prior to this problem started appearing?


unable to connect to remote server:11528

$
0
0

hello,I have a problem.

when I am doing sth on my oarganization software this error is shown.what is solution?Is this related to SQLServer?

unable to connect to remote server :11528

unable to connect to remote server :11527

unable to connect to remote server :11524

unable to connect to remote server :11521

unable to connect to remote server :11520

unable to connect to remote server :11519

Avoid Multiple user select the same row

$
0
0

Dear All,

I want to avoid multiple users select the same row at the same time.

I have used rowlock concept. its not working.

select top(1) * from tablename with (rowlock)


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. 


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?

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!

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


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.


More records (table with one Varchar Max column) causes deadlock with windows services

$
0
0

Hi,

I have a windows service for sending emails by reading email contents from a table including the body (Varchar Max with 40000bytes of data). The windows service will update the status of each record after sending email. My issue exists only of I have records more than say 7500 in the table. That is my windows service will work fine with all updates to table if the number of records in the table is less than 7500 records. If the number of records exceeds 7500 then it cause a deadlock in the table and my windows service will fail to send email. Please help with your suggestions...

Interest Calculation

$
0
0
How to calculation interest on balance at 12PM daily?

SQLServer2012: Load CLR Assembly Targeting Framework 2.0

$
0
0

Hi

i have a .Net Assembly (say Dummy.dll) that depend on a few CLR 2.0 Assemblies (DepA.dll, DepB.dll) that depend on v2.0 System Assemblies.

I need to load this Assembly (and all dependencies) into SQLServer supporting V.2005 to V.2012. I'm unable to recompile the dependencies (DepA.dll, DepB.dll, they are compiled for 2.0 and depend on 2.0 System Assmblies).

With SQLServer V2005-V2008R2 i do the following tasks to install Dummy.dll.:

- Enable clr
- Set Database Trustworthy
- CREATE ASSEMBLY  for all unsupported System Assemblies WITH permission_set = UNSAFE
- CREATE ASSEMBLY  for all dependend assemblies DepA.dll, DepB.dll WITH permission_set = UNSAFE
- CREATE ASSEMBLY Dummy.dll WITH permission_set = UNSAFE

This Works.

I use the same Assembly (Dummy.dll) in a 4.0 WinForm and in a Asp.Net 4.0 Application. Because the 4.0 CLR is backward compatible that works without any problems.
I am not able to load the Assembly (Dummy.dll) nor the dependencies nor the unsupported system assemblies into SQLServer 2012.
How is this possible ?

If the 4.0 Runtime in SqlServer 2012 is not backward compatible, is it possible to force SQLServer 2012 to use the 2.0 Runtime ?

My approach is:
1. For System Assemblies: Load the corresponding 4.0 assemblies instead of the 2.0, 3.0, 3.5 ones.
2. For dependend Assemblies: Try to load them (hope that this works)
3. For Dummy.dll: Try to load the 2.0 Version, if not working, recompile for 4.0 and load that.

I failed already at Step 1

Instead of creating the CLR 2.0 System Assemblies i tried to load the corresponding 4.0 ones.
This works for Sytem.Web.dll but not for WindowsBase.dll.

In SqlServer 2008R2 i load the assembly using the following Statement (on x64):

CREATE ASSEMBLY [WindowsBase] FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll' WITH permission_set = UNSAFE

This Works.

In SqlServer 2012 i used the following Statement:

CREATE ASSEMBLY [WindowsBase] FROM 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\WindowsBase.dll' WITH permission_set = UNSAFE




That gives me the following Error:

Msg 6218, Level 16, State 2, Line 3
CREATE ASSEMBLY for assembly 'WindowsBase' failed because assembly 'WindowsBase' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message
[ : MS.Internal.ResourceIDHelper::GetResourceIDFromRelativePath][mdToken=0x6000001][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.SecurityCriticalDataForSet`1[T]::.ctor][mdToken=0x6000002][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.SecurityCriticalDataForSet`1[T]::get_Value][mdToken=0x6000003][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.SecurityCriticalDataForSet`1[T]::set_Value][mdToken=0x6000004][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::.cctor][mdToken=0x6000012][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::CheckUnmanagedCodePermission][mdToken=0x6000005][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::DemandUnmanagedCode][mdToken=0x6000006][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::DemandRightsManagementPermission][mdToken=0x6000007][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::DemandCompoundFileIOPermission][mdToken=0x6000008][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::DemandPathDiscovery][mdToken=0x6000009][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::RunClassConstructor][mdToken=0x600000a][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::SizeOf][mdToken=0x600000b][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::SizeOf][mdToken=0x600000c][Offset 0x00000000] Die Codegröße ist 0 (null).
[ : MS.Internal.WindowsBase.SecurityHelper::ThrowExceptionForHR][mdT...

I don't know how to get arround this. I tried to load the V3.0 Version, that produces the follwing (expected) error:


Msg 6586, Level 16, State 1, Line 1
Assembly 'WindowsBase' could not be installed because existing policy would keep it from being used.

Any suggestions ?

Thanks Stefan

Achieve tree view in sql tables

$
0
0

Hi,

I have the scenario like some sectors list and the sector having some sub sectors and vice versa.

For Example,

Sectors:

A  

B

C

Sub sectors:

A - 1

     2

     3

Another Sub sector:

2 - AA

     BB

     CC

Maximum four sub sectors possible in the tree view. These scenario need to achieve in sql tables, kindly guide me.

Thanks!

Return Uniqueidentifier from CLR Function

$
0
0

I am creating a CLR function for SQL Server 2008 R2. The CLR function returns anuniqueidentifier, which can sometimes be null. It works when the return value is not null. However, when a null value is returned, SQL Server throws the error Specified cast is not valid.

The function is registered in the database with:

createfunction MyFunc returns uniqueidentifier as external name AssemblyName.UserDefinedFunctions.MyFunc

Example Code

[Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read)]public static Guid MyFunc(){using(SqlConnection con = new SqlConnection("context connection=true")){
    con.Open();using(SqlCommand cmd = new SqlCommand()){
      cmd.Connection = con;
      cmd.CommandText ="select cast('00000000-0000-0000-0000-000000000000' as uniqueidentifier)";//cmd.CommandText ="select cast(null as uniqueidentifier)";return(Guid)cmd.ExecuteScalar();}}}

The first CommandText works, the second throws the Specified cast is not valid error.

I tried changing the return type from Guid to SqlGuid on lines 2 and 12, but then SQL Server always throws the Specified cast is not valid error, regardless whether the value is null or not.

Question

What is the proper way to return a uniqueidentifier from a CLR function when the return value is sometimes null?

Viewing all 780 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>