在ms sql server 安装目录下有个可执行文件叫 textcopy.exe
可对 ms sql server 中的文本或图像数据进行输入输出.
不过你可以在ms-dos方式下执行textcopy /? 得到它的描述。
下面是这个工具的描述:
copies a single text or image value into or out of sql server. the val
ue
is a specified text or image 'column' of a single row (specified by th
e
"where clause") of the specified 'table'.
if the direction is in (/i) then the data from the specified 'file' is
copied into sql server, replacing the existing text or image value. if
the
direction is out (/o) then the text or image value is copied from
sql server into the specified 'file', replacing any existing file.
textcopy [/s ][sqlserver]] [/u [login]] [/p ][password]]
[/d ][database]] [/t table] [/c column] [/w"where clause"]
[/f file] [{/i | /o}] [/k chunksize] [/z] [/?]
/s sqlserver the sql server to connect to. if 'sqlserver' is n
ot
specified, the local sql server is used.
/u login the login to connect with. if 'login' is not spec
ified,
a trusted connection will be used.
/p password the password for 'login'. if 'password' is not
specified, a null password will be used.
/d database the database that contains the table with the tex
t or
image data. if 'database' is not specified, the d
efault
database of 'login' is used.
/t table the table that contains the text or image value.
/c column the text or image column of 'table'.
/w "where clause" a complete where clause (including the where keyw
ord)
that specifies a single row of 'table'.
/f file the file name.
/i copy text or image value into sql server from 'fi
le'.
/o copy text or image value out of sql server into '
file'.
/k chunksize size of the data transfer buffer in bytes. minimu
m
value is 1024 bytes, default value is 4096 bytes.
/z display debug information while running.
/? display this usage information and exit.
you will be prompted for any required options you did not specify.
为此, 可写一个存储过程,调用这个命令
create procedure sp_textcopy (
@srvname varchar (30),
@login varchar (30),
@password varchar (30),
@dbname varchar (30),
@tbname varchar (30),
@colname varchar (30),
@filename varchar (30),
@whereclause varchar (40),
@direction char(1))
as
declare @exec_str varchar (255)
select @exec_str =
'textcopy /s ' + @srvname +
' /u ' + @login +
' /p ' + @password +
' /d ' + @dbname +
' /t ' + @tbname +
' /c ' + @colname +
' /w "' + @whereclause +
'" /f ' + @filename +
' /' + @direction
exec master..xp_cmdshell @exec_str
下面是一个拷贝图像到sql server的pubs数据库的例子, 表名pub_info, 字段名
logo,图像文件名picture.bmp,保存到pub_id='0736'记录 sp_textcopy @srvn
ame = 'servername',
@login = 'login',
@password = 'password',
@dbname = 'pubs',
@tbname = 'pub_info',
@colname = 'logo',
@filename = 'c:/picture.bmp',
@whereclause = " where pub_id='0736' ",
@direction = 'i'
新闻热点
疑难解答