简体   繁体   English

使用VBScript将二进制文件上传到已启用文件流的表(来自cmd)

[英]Uploading a binary file to a filestream enabled table using VBScript (from cmd)

I want to insert a binary file into a filestream enabled (remote) database using VBScript (from cmd prompt, using cscript). 我想使用VBScript(在cmd提示符下,使用cscript)将二进制文件插入已启用文件流(远程)的数据库中。 My code works when I'm testing on my local db, but because the code was using: 当我在本地数据库上进行测试时,我的代码可以工作,但是因为代码正在使用:

INSERT........ * FROM OPENROWSET(BULK '"&objFile.Path&"', SINGLE_BLOB)

the file has to be a local file (ie on the machine the SQL server is on). 该文件必须是本地文件(即在SQL Server所在的计算机上)。 I need to upload from my machine to a remote SQL file. 我需要从计算机上载到远程SQL文件。 Here's where I got to so far: Wscript.Echo "Attempting to upload "& objFile.Name &" from folder "& objsubFolder.Name 到目前为止,这是我到达的地方:Wscript.Echo“试图从文件夹“&objsubFolder.Name”上载“&objFile.Name&”

binstream.open
binstream.LoadFromFile objFile.Path

myCommand.CommandText = "INSERT INTO DBNAME (TimeStamp, FileName, Data)" &_
"SELECT '"&objsubFolder.Name&"' AS TimeStamp," &_
"'"&objFile.Name&"' AS FileName," &_
"'"&binstream.Read&"' AS Data"
myCommand.Execute

binstream.close

However the error I get returned is: "Microsoft VBScript runtime error: Type mismatch" 但是,我得到的错误是:“ Microsoft VBScript运行时错误:类型不匹配”

Which I presume is me being silly because I'm trying to insert a binary file by just sticking it into the insert sql statement. 我以为我很傻,因为我试图通过将二进制文件粘贴到插入sql语句中来插入二进制文件。 How do I work around this and get it to upload my file? 我该如何解决并使它上传我的文件?

Thanks in advance for the help. 先谢谢您的帮助。

IMO The easiest way is keeping your code that works for uploading a local file since that works and make sure the file is local by copying the file to the server first on a share. IMO最简单的方法是保留可用于上载本地文件的代码,因为这样做可以正常工作,并通过首先将文件复制到共享服务器上来确保文件是本地文件。 Then run the sql you tested from your script on the server, the copying could also be done from the server if the user which runs the script has sufficient privileges to access your file on the other pc or by putting it on a share that can be read. 然后在服务器上运行通过脚本测试的sql,如果运行脚本的用户具有足够的特权来访问另一台PC上的文件或将其放在可以共享的共享上,则也可以从服务器上进行复制。读。 Executing the script on the server can be done by a schedule, a script that monitors a folder or by remote scripting or PSFILE 可以通过时间表,监视文件夹的脚本或通过远程脚本或PSFILE来执行服务器上的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM