dqq48152418 2010-03-16 15:21
浏览 81
已采纳

将二进制数据传递给SQL Server 2008中的存储过程

I'm trying to figure out a way to store files in a database. I know it's recommended to store files on the file system rather than the database, but the job I'm working on would highly prefer using the database to store these images (files).

There are also some constraints. I'm not an admin user, and I have to make stored procedures to execute all the commands. This hasn't been of much difficulty so far, but I cannot for the life of me establish a way to store a file (image) in the database.

When I try to use the BULK command, I get an error saying "You do not have permission to use the bulk load statement." The bulk utility seemed like the easy way to upload files to the database, but without permissions I have to figure a work-a-round.

I decided to use an HTML form with a file upload input type and handle it with PHP. The PHP calls the stored procedure and passes in the contents of the file. The problem is that now it's saying that the max length of a parameter can only be 128 characters.

Now I'm completely stuck. I don't have permissions to use the bulk command and it appears that the max length of a parameter that I can pass to the SP is 128 characters.

I expected to run into problems because binary characters and ascii characters don't mix well together, but I'm at a dead end...

Thanks

  • 写回答

2条回答 默认 最新

  • dongmeng1402 2010-03-16 16:55
    关注

    Here is an example I've found in David Hayden's blog.

    It's a c# example, but the steps should be similar in PHP:

    1. Convert your uploaded file to a byte array
    2. Execute dynamic TSQL on the server
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?