Showing posts with label common. Show all posts
Showing posts with label common. Show all posts

Thursday, March 22, 2012

Error deploying managed stored proc

When I try to deploy this managed stored proc assembly on SQL Server 2005 I get this error:

Failed to initialize the Common Language Runtime (CLR) v2.0.50727 with HRESULT 0x8007000e. You may fix the problem and try again later

I looked on the net but found no documentation about it. I know the CLR v2.0 is working as I have some ASP.NET apps running from this server that use it. Any ideas?

Try the simple code to get a .dll file:

using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;

public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure()]
public static void SampleSP(string connstring, out int spid)
{
using (SqlConnection conn = new SqlConnection(connstring))
{
conn.Open();

SqlCommand cmd = new SqlCommand("SELECT @.@.SPID", conn);
spid = (System.Int16)cmd.ExecuteScalar();
}
}
}

And then let's manually create assmebly from the dll file in Management Studio:

1. Login to SQL2005 as 'sa', locate a database->new query->execute following command:

alter database yourdb set trustworthy on

go

sp_configure 'clr enabled',1
reconfigure with override

go

2. create an assembly from the dll file

3. create a stored procedure which references the assembly:

create procedure testCLR @.conn nvarchar(max),@.i int output as
external name ClassLibrary2.[StoredProcedures].SampleSP

4. Test the procedure:

declare @.i int

exec testCLR 'Data Source=.;Integrated Security=SSPI;Database=master',@.i output

select @.i

And here is a good torturial for using CLR in SQL2005:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/mandataaccess.asp

Friday, February 17, 2012

Error at: The user is not associated with a trusted SQL Server connection

Hi I've got a common error using SQL server 2005

"The user is not associated with a trusted SQL Server connection"

I'm building a application using C# when using a standalone environment, it worked well. But, now I have the following environment.

A.
SQL server
Domain XXX

B. Remote machine
Application
Domain YYY

I changed SQL server to support SQL and WIN authentication mode and I have changed SQl server surface area configuration to support TCP/IP and Named Pipes for remote connections. But I still have two problems:

1. When using the IP - serverName of the dataserver, the error is

System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection..

1. When using the server name(MYServerName), I have this error:
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Besides, I have tried from my remote machine to use a sqlcmd -E -S tcp:myhost command but I have the same answer.

Any help, I will thank.I believe you set Mixed Authentication in your SQL server in the domain XXX.
And you have an NT login in the application YYY domain.

You could try two things:

Check if you have the same NT login in XXX domain.
The XXX domain needs to trust the YYY domain to allow this to occur. You
could use SQL Server authentication instead if you don't want this trust to
occur. Trouble is you need to pass the password for the SQL login, but worth to try.|||this should work as long as the xxx domain trusts the yyy domain. if it doesn't, windows auth won't work.

is it possible to login to a box in XXX with an nt account in YYY? if not then there is no trust.