从 SQL Server varbinary 列临时检索数据
我想从 SQL Server 数据库中的 varbinary(max)
列检索一些二进制数据以进行调试。
将此数据放入本地二进制文件的最简单方法是什么,最好无需编写一次性控制台应用程序?
我尝试使用 SQL Server Management Studio(使用“结果到文件”选项),但这会向文件输出十六进制编码的二进制字符串,而不是原始二进制数据。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想不出比扔掉一些 C# 更简单的方法了...
此代码已在带有 Reporting Services 的 SQL Server 默认安装中使用 Users.Sid 列(属于 varbinary 类型)进行了测试。
I can't think of any easier way to do this than a throw away bit of C#...
This code has been tested using the Users.Sid column (which is of varbinary type) in a default installation of SQL Server wih Reporting Services.
我喜欢 LinqPad 的建议。我尝试了一下,并有一个查询在 10 分钟内将二进制文件吐出到一个文件中。没有 VS 项目,没有构建 - 现在脚本已保存,我可以随时提取它。太酷了!
LinqPad 脚本:
I loved the LinqPad suggestion. I tried it and had a query that spit out the binary to a file within 10 minutes. No VS Project, no build - and now the script is saved and I can pull it up anytime. So cool!
LinqPad script:
我找到了这个解决方案使用 bcp 命令(从命令提示符运行):
我使用 -T 选项来使用 Windows 身份验证来连接到数据库。如果您使用密码身份验证,则需要使用 -U 和 -P 开关来指定用户名和密码。
但我也喜欢 LinqPad 建议/281048">罗布·萨德勒的回答并且不知何故更喜欢它。
I've found this solution with
bcp
command (run from command prompt):I used the -T option to use windows authentication to connect to the DB. If you use password auth, you'll need to use the -U and -P switches to specify a username and password.
But I also like LinqPad suggestion in Robb Sadler's answer and somehow prefer it.