Given below is a way to access the file contents of a database server using the latest feature of SQL Server 2005 called CLR integration.

The theory and source code can be accessed from http://blogs.msdn.com/sqlclr/archive/20 ... 15034.aspx.

The compilation is quite staraight forward and all you need to do is create a dll file from the C# code by creating a Class Library.

You may face some problems giving the assembly external_access.

The error maybe something like

Msg 10327, Level 14, State 1, Line 1
CREATE ASSEMBLY for assembly 'TVF' failed because assembly 'TVF' is not authorized for PERMISSION_SET = EXTERNAL_ACCESS. The assembly is authorized when either of the following is true: the database owner (DBO) has EXTERNAL ACCESS ASSEMBLY permission and the database has the TRUSTWORTHY database property on; or the assembly is signed with a certificate or an asymmetric key that has a corresponding login with EXTERNAL ACCESS ASSEMBLY permission. If you have restored or attached this database, make sure the database owner is mapped to the correct login on this server. If not, use sp_changedbowner to fix the problem.

In my case I was executing the statements as an administrator hence the database owner had the EXTERNAL ACCESS ASSEMBLY permission so all I needed to do was alter the database to make it trustworthy by executing the command

alter database {database name} set trustworthy on

You may also be required to set the database compatibility level to the highest value using :-

sp_dbcmptlevel {database name} , 90

Note :- Make sure that you set the Enable CLR Integration option in the Surface Area Configuration to true.