views:

83

answers:

3

I have a text file sitting on client machine and want to move it to the database server (MS SQL 2008) but I don't have any access to the server except through the SQL Server client. Can I transfer this file to the server using SQL client connection?

A: 

Do you want to put it in the database, or in the filesystem? If the former, consider a text or varchar(max).

If the latter, use SQL injection and xp_cmdshell as needed. :) Actually, in this case you should ask the admin for a more appropriate transfer mechanism.

Matthew Flaschen
is xp_cmdshell better then writing extended stored procedure?
wasim
+2  A: 

Yes you can do it but not through standard SQL. You will have to write an extended stored procedure that will alow you to connect through sql client connection and to access server file system. But you will have to address a lot of user privileges issues.

Leslie Norman
is extended stored procedure better then using xp_cmdshell that Mathew suggested?
wasim
xp_cmdShell has limitations of at most 8000 chars while you have better control on extended/CLR procedure
Leslie Norman
Thank you Steve. It looks cool. I give it a try and see how it works
wasim
I've never used it but saw it recommended around here: FILESTREAM - http://technet.microsoft.com/en-us/library/bb933993.aspx
IMHO
A: 

If you want to save the file into the database then is a no brainer.

If you want to save into the file system the use a CLR stored procedure marked as having EXTERNAL_ACCESS. You can pass a BLOB parameter to the procedure and the procedure in turn can write the BLOB content to the disk, using ordinary FileStream operations. If the file is very large then special care needs to be taken to prevent memory bloat.

Remus Rusanu