Thursday, March 8, 2012

.NET exception whenn calling CLR user-defined functions

Hi Mike,
This error can happen when the database has been detached and attached onto
a different server and SQL Server is unable to find the correct login
associated with the dbo for that database. If this is the case for you,
then you can fix the problem by using sp_changedbowner to reassociate dbo
with a valid login like so: exec sp_changedbowner 'sa'. Making the error
message more clear is on track to be fixed in a future service pack. Hope
this helps.
Steven
"FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
news:537F22F0-200F-4D1C-96AD-E7A211C75644@.microsoft.com...
> hello together!
> currently we are developing a server database which is using an assembly
> with some very simple clr-functions (eg check regular expression or
> converting local time to universal time).
> from some indefinite time we receive the following errormessage each time
> calling such a clr-function:
> Msg 10314, Level 16, State 11, Line 1
> An error occurred in the Microsoft .NET Framework while trying to load
> assembly id 65706. The server may be running out of resources, or the
> assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or
> UNSAFE.
> Run the query again, or check documentation to see how to solve the
> assembly
> trust issues. For more information about this error:
> System.IO.FileNotFoundException: Could not load file or assembly
> 'myassembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one
> of
> its dependencies. The system cannot find the file specified.
> System.IO.FileNotFoundException:
> at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
> codeBase, Evidence assemblySecurity, Assembly locationHint,
> StackCrawlMark&
> stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
> at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
> Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
> forIntrospection)
> at System.Reflection.Assembly.InternalLoad(String assemblyString,
> Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
> forIntrospection)
> at System.Reflection.Assembly.Load(String assemblyString)
> the only way to get the assembly working again is to restart the sql
> server
> engine or the whole server.
> sometimes even multiple restarts are needed.
> we tried several things to get rid of this message but without any access:
> - drop and re-create the assembly and all functions in the database (with
> visual studio deployment, with t-sql statements loading the assembly from
> a
> file or in binary)
> - change of the assembly permission_set according to the error message
> (even
> there is no external access or unsafe code - there is even no database
> access
> at all)
> - restrict the maximum server memory at the server options
> - we already tried to setup the whole database on a complete different
> independent server with a complete fresh sql server installation
> - update the sql server with service pack 1
> - building the assembly with platform x64 instead of any cpu
> configuration of our two test systems
> - WIN2003 SP1 ENT + SQL2005 STD X64 RTM clustered
> - WIN2003 SP1 ENT + SQL2005 DEV X64 SP1 single
> any ideas or recommendation regarding this problem? - thanks in advance
> mike s.hello together!
currently we are developing a server database which is using an assembly
with some very simple clr-functions (eg check regular expression or
converting local time to universal time).
from some indefinite time we receive the following errormessage each time
calling such a clr-function:
Msg 10314, Level 16, State 11, Line 1
An error occurred in the Microsoft .NET Framework while trying to load
assembly id 65706. The server may be running out of resources, or the
assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE.
Run the query again, or check documentation to see how to solve the assembly
trust issues. For more information about this error:
System.IO.FileNotFoundException: Could not load file or assembly
'myassembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one o
f
its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException:
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark&
stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
the only way to get the assembly working again is to restart the sql server
engine or the whole server.
sometimes even multiple restarts are needed.
we tried several things to get rid of this message but without any access:
- drop and re-create the assembly and all functions in the database (with
visual studio deployment, with t-sql statements loading the assembly from a
file or in binary)
- change of the assembly permission_set according to the error message (even
there is no external access or unsafe code - there is even no database acces
s
at all)
- restrict the maximum server memory at the server options
- we already tried to setup the whole database on a complete different
independent server with a complete fresh sql server installation
- update the sql server with service pack 1
- building the assembly with platform x64 instead of any cpu
configuration of our two test systems
- WIN2003 SP1 ENT + SQL2005 STD X64 RTM clustered
- WIN2003 SP1 ENT + SQL2005 DEV X64 SP1 single
any ideas or recommendation regarding this problem? - thanks in advance
mike s.|||Hi Mike,
This error can happen when the database has been detached and attached onto
a different server and SQL Server is unable to find the correct login
associated with the dbo for that database. If this is the case for you,
then you can fix the problem by using sp_changedbowner to reassociate dbo
with a valid login like so: exec sp_changedbowner 'sa'. Making the error
message more clear is on track to be fixed in a future service pack. Hope
this helps.
Steven
"FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
news:537F22F0-200F-4D1C-96AD-E7A211C75644@.microsoft.com...
> hello together!
> currently we are developing a server database which is using an assembly
> with some very simple clr-functions (eg check regular expression or
> converting local time to universal time).
> from some indefinite time we receive the following errormessage each time
> calling such a clr-function:
> Msg 10314, Level 16, State 11, Line 1
> An error occurred in the Microsoft .NET Framework while trying to load
> assembly id 65706. The server may be running out of resources, or the
> assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or
> UNSAFE.
> Run the query again, or check documentation to see how to solve the
> assembly
> trust issues. For more information about this error:
> System.IO.FileNotFoundException: Could not load file or assembly
> 'myassembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one
> of
> its dependencies. The system cannot find the file specified.
> System.IO.FileNotFoundException:
> at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
> codeBase, Evidence assemblySecurity, Assembly locationHint,
> StackCrawlMark&
> stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
> at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
> Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
> forIntrospection)
> at System.Reflection.Assembly.InternalLoad(String assemblyString,
> Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
> forIntrospection)
> at System.Reflection.Assembly.Load(String assemblyString)
> the only way to get the assembly working again is to restart the sql
> server
> engine or the whole server.
> sometimes even multiple restarts are needed.
> we tried several things to get rid of this message but without any access:
> - drop and re-create the assembly and all functions in the database (with
> visual studio deployment, with t-sql statements loading the assembly from
> a
> file or in binary)
> - change of the assembly permission_set according to the error message
> (even
> there is no external access or unsafe code - there is even no database
> access
> at all)
> - restrict the maximum server memory at the server options
> - we already tried to setup the whole database on a complete different
> independent server with a complete fresh sql server installation
> - update the sql server with service pack 1
> - building the assembly with platform x64 instead of any cpu
> configuration of our two test systems
> - WIN2003 SP1 ENT + SQL2005 STD X64 RTM clustered
> - WIN2003 SP1 ENT + SQL2005 DEV X64 SP1 single
> any ideas or recommendation regarding this problem? - thanks in advance
> mike s.|||hi steven,
first many thanks for your quick response and support!
you're right the database has been detached and attached on different
servers during development many times
can i check this case with the system catalog views?
when i take a look at the sys.databases catalog view the owner_sid is 0x01 -
according to the sys.server_principals and sys.database_principals views the
sid 0x01 belongs to the login sa and the user dbo
anyway i will try to change the dbo according to your statement and hope
that this error won't occur in the future
thanks again,
mike s.
"Steven Hemingray [MSFT]" wrote:

> Hi Mike,
> This error can happen when the database has been detached and attached ont
o
> a different server and SQL Server is unable to find the correct login
> associated with the dbo for that database. If this is the case for you,
> then you can fix the problem by using sp_changedbowner to reassociate dbo
> with a valid login like so: exec sp_changedbowner 'sa'. Making the error
> message more clear is on track to be fixed in a future service pack. Hope
> this helps.
> Steven
>
> "FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
> news:537F22F0-200F-4D1C-96AD-E7A211C75644@.microsoft.com...
>
>|||hi again,
after changing the dbo like you describe above it only takes some hours and
now the error occurs again
any other ideas or suggestions?
thanks in advance,
mike
"FwMsdn" wrote:
[vbcol=seagreen]
> hi steven,
> first many thanks for your quick response and support!
> you're right the database has been detached and attached on different
> servers during development many times
> can i check this case with the system catalog views?
> when i take a look at the sys.databases catalog view the owner_sid is 0x01
-
> according to the sys.server_principals and sys.database_principals views t
he
> sid 0x01 belongs to the login sa and the user dbo
> anyway i will try to change the dbo according to your statement and hope
> that this error won't occur in the future
> thanks again,
> mike s.
> "Steven Hemingray [MSFT]" wrote:
>|||hi steven,
first many thanks for your quick response and support!
you're right the database has been detached and attached on different
servers during development many times
can i check this case with the system catalog views?
when i take a look at the sys.databases catalog view the owner_sid is 0x01 -
according to the sys.server_principals and sys.database_principals views the
sid 0x01 belongs to the login sa and the user dbo
anyway i will try to change the dbo according to your statement and hope
that this error won't occur in the future
thanks again,
mike s.
"Steven Hemingray [MSFT]" wrote:

> Hi Mike,
> This error can happen when the database has been detached and attached ont
o
> a different server and SQL Server is unable to find the correct login
> associated with the dbo for that database. If this is the case for you,
> then you can fix the problem by using sp_changedbowner to reassociate dbo
> with a valid login like so: exec sp_changedbowner 'sa'. Making the error
> message more clear is on track to be fixed in a future service pack. Hope
> this helps.
> Steven
>
> "FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
> news:537F22F0-200F-4D1C-96AD-E7A211C75644@.microsoft.com...
>
>|||hi again,
after changing the dbo like you describe above it only takes some hours and
now the error occurs again
any other ideas or suggestions?
thanks in advance,
mike
"FwMsdn" wrote:
[vbcol=seagreen]
> hi steven,
> first many thanks for your quick response and support!
> you're right the database has been detached and attached on different
> servers during development many times
> can i check this case with the system catalog views?
> when i take a look at the sys.databases catalog view the owner_sid is 0x01
-
> according to the sys.server_principals and sys.database_principals views t
he
> sid 0x01 belongs to the login sa and the user dbo
> anyway i will try to change the dbo according to your statement and hope
> that this error won't occur in the future
> thanks again,
> mike s.
> "Steven Hemingray [MSFT]" wrote:
>|||The way to check for the problem is to see if the owner_sid in sys.databases
does not match the sid for dbo in sys.database_principals.
use YOUR_DATABASE
go
select d.name, dp.name, d.owner_sid, dp.sid from sys.databases d,
sys.database_principals dp where d.owner_sid = dp.sid and dp.name = 'dbo'
and d.name = 'YOUR_DATABASE'
If you're still seeing this problem and the above query indicates that the
sids match, then it must be a different problem and I'd have to do some
investigation on what else could cause this to fail repeatedly and on
different independent servers.
Steven
"FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
news:EB0942FA-39B3-4590-B7F8-73D59A1A0794@.microsoft.com...[vbcol=seagreen]
> hi again,
> after changing the dbo like you describe above it only takes some hours
> and
> now the error occurs again
> any other ideas or suggestions?
> thanks in advance,
> mike
> "FwMsdn" wrote:
>|||The way to check for the problem is to see if the owner_sid in sys.databases
does not match the sid for dbo in sys.database_principals.
use YOUR_DATABASE
go
select d.name, dp.name, d.owner_sid, dp.sid from sys.databases d,
sys.database_principals dp where d.owner_sid = dp.sid and dp.name = 'dbo'
and d.name = 'YOUR_DATABASE'
If you're still seeing this problem and the above query indicates that the
sids match, then it must be a different problem and I'd have to do some
investigation on what else could cause this to fail repeatedly and on
different independent servers.
Steven
"FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
news:EB0942FA-39B3-4590-B7F8-73D59A1A0794@.microsoft.com...[vbcol=seagreen]
> hi again,
> after changing the dbo like you describe above it only takes some hours
> and
> now the error occurs again
> any other ideas or suggestions?
> thanks in advance,
> mike
> "FwMsdn" wrote:
>|||hi steven,
as mentioned in an earlier post the dbo mapping seems to be ok (according to
the system catalog views)
here is the result of your statement similar to my query
Name name owner_sid sid
Core dbo 0x01 0x01
what else can i try?
mike
"Steven Hemingray [MSFT]" wrote:

> The way to check for the problem is to see if the owner_sid in sys.databas
es
> does not match the sid for dbo in sys.database_principals.
> use YOUR_DATABASE
> go
> select d.name, dp.name, d.owner_sid, dp.sid from sys.databases d,
> sys.database_principals dp where d.owner_sid = dp.sid and dp.name = 'dbo'
> and d.name = 'YOUR_DATABASE'
> If you're still seeing this problem and the above query indicates that the
> sids match, then it must be a different problem and I'd have to do some
> investigation on what else could cause this to fail repeatedly and on
> different independent servers.
> Steven
>
> "FwMsdn" <FwMsdn@.discussions.microsoft.com> wrote in message
> news:EB0942FA-39B3-4590-B7F8-73D59A1A0794@.microsoft.com...
>
>

No comments:

Post a Comment